CSES - COCI 2007/2008 #1 - Results
Submission details
Task:Zapis
Sender:henrikaalto
Submission time:2019-07-29 15:44:35 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails
#40.02 sdetails
#50.07 sdetails
#60.21 sdetails
#70.05 sdetails
#80.02 sdetails
#90.03 sdetails
#100.02 sdetails

Code

// :E
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
using ii=long long;


const int N = 205;


int dp[2][N][N][N]; // (, [, {
int pd[2][N][N][N];

int z = 0;

const int mod = 1e5;

int lol = 0;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (s[0] == '?') {
        dp[z][1][0][0] = 1;
        dp[z][0][1][0] = 1;
        dp[z][0][0][1] = 1;
    }
    if (s[0] == '(') {
        dp[z][1][0][0] = 1;
    }
    if (s[0] == '[') {
        dp[z][0][1][0] = 1;
    }
    if (s[0] == '{') {
        dp[z][0][0][1] = 1;
    }
        for (int j = 0; j < n; ++j) {
            for (int h = 0; h < n; ++h) {
                for (int k = 0; k < n; ++k) {
                    //printf("dp[%d][%d][%d] = %d\n", j, h, k, dp[z][j][h][k]);
                }
            }
        }
        //printf("\n\n");
    for (int i = 1; i < n; ++i) {
        z = !z;
        for (int j = 0; j < n; ++j) {
            for (int h = 0; h < n; ++h) {
                for (int k = 0; k < n; ++k) {
                    dp[z][j][h][k] = 0;
                    pd[z][j][h][k] = 0;
                }
            }
        }
        if (s[i] == '?') {
            for (int j = 0; j < n; ++j) {
                for (int h = 0; h < n; ++h) {
                    for (int k = 0; k < n; ++k) {
                        if (j > 0) {
                            dp[z][j][h][k] += dp[!z][j - 1][h][k];
                            //printf("dp[%d][%d][%d] += dp[%d][%d][%d]\n", j, h, k, j - 1, h, k);
                            pd[z][j][h][k] |= pd[!z][j - 1][h][k];
                        }
                        if (h > 0) {
                            dp[z][j][h][k] += dp[!z][j][h - 1][k];
                            //printf("dp[%d][%d][%d] += dp[%d][%d][%d]\n", j, h, k, j, h - 1, k);
                            pd[z][j][h][k] |= pd[!z][j][h - 1][k];
                        }
                        if (k > 0) {
                            dp[z][j][h][k] += dp[!z][j][h][k - 1];
                            //printf("dp[%d][%d][%d] += dp[%d][%d][%d]\n", j, h, k, j, h, k - 1);
                            pd[z][j][h][k] |= pd[!z][j][h][k - 1];
                        }
                        dp[z][j][h][k] += dp[!z][j + 1][h][k];
                        //printf("dp[%d][%d][%d] += dp[%d][%d][%d]\n", j, h, k, j + 1, h, k);
                        pd[z][j][h][k] |= pd[!z][j + 1][h][k];
                        dp[z][j][h][k] += dp[!z][j][h + 1][k];
                        //printf("dp[%d][%d][%d] += dp[%d][%d][%d]\n", j, h, k, j, h+1, k);
                        pd[z][j][h][k] |= pd[!z][j][h + 1][k];
                        dp[z][j][h][k] += dp[!z][j][h][k + 1];
                        //printf("dp[%d][%d][%d] += dp[%d][%d][%d]\n", j, h, k, j, h, k+1);
                        pd[z][j][h][k] |= pd[!z][j][h][k + 1];
                        if (dp[z][j][h][k] >= mod) {
                            pd[z][j][h][k] = 1;
                        }
                        dp[z][j][h][k] %= mod;
                    }
                }
            }
        }
        else {
            for (int j = 0; j < n; ++j) {
                for (int h = 0; h < n; ++h) {
                    for (int k = 0; k < n; ++k) {
                        if (s[i] == ')') {
                            dp[z][j][h][k] += dp[!z][j + 1][k][h];
                            pd[z][j][h][k] |= pd[!z][j + 1][k][h];
                        }
                        if (s[i] == '(') {
                            if (j > 0) {
                                dp[z][j][h][k] += dp[!z][j - 1][k][h];
                                pd[z][j][h][k] |= pd[!z][j - 1][k][h];
                            }
                        }
                        if (s[i] == ']') {
                            dp[z][j][h][k] += dp[!z][j][k + 1][h];
                            pd[z][j][h][k] |= pd[!z][j][k + 1][h];
                        }
                        if (s[i] == '[') {
                            if (k > 0) {
                                dp[z][j][h][k] += dp[!z][j][k - 1][h];
                                pd[z][j][h][k] |= pd[!z][j][k - 1][h];
                            }
                        }
                        if (s[i] == '}') {
                            dp[z][j][h][k] += dp[!z][j][k][h + 1];
                            pd[z][j][h][k] |= pd[!z][j][k][h + 1];
                        }
                        if (s[i] == '{') {
                            if (h > 0) {
                                dp[z][j][h][k] += dp[!z][j][k][h - 1];
                                pd[z][j][h][k] |= pd[!z][j][k][h - 1];
                            }
                        }
                        if (dp[z][j][h][k] >= mod) {
                            pd[z][j][h][k] = 1;
                        }
                        dp[z][j][h][k] %= mod;
                    }
                }
            }
        }
        for (int j = 0; j < n; ++j) {
            for (int h = 0; h < n; ++h) {
                for (int k = 0; k < n; ++k) {
                    //printf("dp[%d][%d][%d] = %d\n", j, h, k, dp[z][j][h][k]);
                }
            }
        }
        //printf("\n\n");
    }
    if (pd[z][0][0][0]) printf("%05d\n", dp[z][0][0][0]);
    else printf("%d\n", dp[z][0][0][0]);
}

Test details

Test 1

Verdict:

input
6
??]{??

correct output
3

user output
9

Test 2

Verdict:

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

correct output
6

user output
40

Test 3

Verdict:

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

correct output
186

user output
7572

Test 4

Verdict:

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

correct output
315

user output
2944

Test 5

Verdict:

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

correct output
00004

user output
24934

Test 6

Verdict:

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

correct output
59479

user output
03748

Test 7

Verdict:

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

correct output
2

user output
(empty)

Test 8

Verdict:

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

correct output
47279

user output
(empty)

Test 9

Verdict:

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

correct output
68283

user output
(empty)

Test 10

Verdict:

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

correct output
24

user output
(empty)