CSES - COCI 2007/2008 #1 - Results
Submission details
Task:Zapis
Sender:henrikaalto
Submission time:2019-07-31 17:43:35 +0300
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.02 sdetails
#9ACCEPTED0.03 sdetails
#10ACCEPTED0.03 sdetails

Compiler report

input/code.cpp: In function 'int match(char, char)':
input/code.cpp:43:15: warning: array subscript has type 'char' [-Wchar-subscripts]
     return q[a] == b;
               ^
input/code.cpp: In function 'mint hae(int, int, int)':
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
     mint &r = dp[a][b][c];
               ~~~~~~~~~~^
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code.cpp:62:25: warning: array subscript is outside array bounds [-Warray-bounds]
input/code...

Code

#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define debug(...) #__VA_ARGS__ << ": " << __VA_ARGS__
using ii=long long;
const ii mod=1e5;
struct mint {
    ii val;
    int over = 0;
    mint() {
        val = 0;
        over = 0;
    }
    mint(int x)
    {
        val = x;
    }
    mint &operator+=(const mint &b)
    {
        over |= b.over;
        if((val += b.val) >= mod) over = 1;
        val %= mod;
        return *this;
    }
    mint &operator*=(const mint &b)
    {
        over |= b.over;
        if((val *= b.val) >= mod) over = 1;
        val %= mod;
        return *this;
    }
    friend mint operator*(mint a, const mint &b)
    {
        return a *= b;
    }
};
int n;
char d[222],q[222];
mint dp[222][222][2];
int pd[222][222][2];
int match(char a, char b)
{
    return q[a] == b;
}
int fl(char a)
{
    return a == '(' || a == '[' || a == '{';
}
int fr(char a)
{
    return !fl(a);
}
mint hae(int a, int b, int c = 3)
{
    if (b & 1) return dp[a][b][c];
    if (b == 0) {
        dp[a][b][c].val = 1;
        return dp[a][b][c];
    }
    if (pd[a][b][c]) return dp[a][b][c];
    pd[a][b][c] = 1;
    mint &r = dp[a][b][c];
    if (c & 1) {
        mint x = hae(a + 1, b - 2);
        int ok = (d[a] == '?' && d[a + b - 1] != '?' && fr(d[a + b - 1]));
        ok |= (d[a] != '?' && d[a + b - 1] == '?' && fl(d[a]));
        ok |= (d[a] != '?' && d[a + b - 1] != '?' && match(d[a], d[a + b - 1]));
        if (ok) r = x;
        else if (d[a] == '?' && d[a + b - 1] == '?') r = mint(3) * x;
    }
    if (c & 2) {
        for (int i = 2; i < b; i += 2) {
            r += hae(a, i, 1) * hae(a + i, b - i, 2);
            r += hae(a, i, 1) * hae(a + i, b - i, 1);
        }
    }
    return dp[a][b][c];
}
int main()
{
    q['('] = ')';
    q['['] = ']';
    q['{'] = '}';
    cin >> n >> (d + 1);
    mint z = hae(1, n);
    printf((z.over ? "%05lld\n" : "%lld\n"), z.val);
}

Test details

Test 1

Verdict: ACCEPTED

input
6
??]{??

correct output
3

user output
3

Test 2

Verdict: ACCEPTED

input
10
??)??{?]()

correct output
6

user output
6

Test 3

Verdict: ACCEPTED

input
20
??[]]??{{??}}((?))??

correct output
186

user output
186

Test 4

Verdict: ACCEPTED

input
30
(?([](??)[])?)]?()?{?[]([])???...

correct output
315

user output
315

Test 5

Verdict: ACCEPTED

input
50
([[[???[]?[??][??]?{??({})]??{...

correct output
00004

user output
00004

Test 6

Verdict: ACCEPTED

input
66
???(??(??[?????[?][???(?{[????...

correct output
59479

user output
59479

Test 7

Verdict: ACCEPTED

input
130
((((?][]))([[[{[(?]}(?})??()]{...

correct output
2

user output
2

Test 8

Verdict: ACCEPTED

input
166
?????????]??????)??{??????(???...

correct output
47279

user output
47279

Test 9

Verdict: ACCEPTED

input
198
?(?{?{?{{????}}????(??{}(?????...

correct output
68283

user output
68283

Test 10

Verdict: ACCEPTED

input
200
[[[({(({[][]})[]){{?{{[]}}}()(...

correct output
24

user output
24