Task: | Zapis |
Sender: | henrikaalto |
Submission time: | 2019-07-31 17:45:38 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.03 s | details |
#10 | ACCEPTED | 0.03 s | details |
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; ^
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][4]; int pd[222][222][4]; 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 |