QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53780 | #2927. Bracket Pairing | abdelrahman001# | AC ✓ | 2ms | 3744kb | C++ | 1.2kb | 2022-10-05 22:16:45 | 2022-10-05 22:16:47 |
Judging History
answer
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 1e4 + 5;
string s, sl = {'?', '(', '{', '[', '<'};
ll memo[20][20];
char ok(char x, char y) {
if(y == '?')
return x == '?' || !count(sl.begin(), sl.end(), x);
if(y == '(')
return x == '?' || x == ')';
if(y == '{')
return x == '?' || x == '}';
if(y == '[')
return x == '?' || x == ']';
return x == '?' || x == '>';
}
ll solve(int l, int r) {
if(l > r)
return 1;
ll &ans = memo[l][r];
if(~ans)
return ans;
ans = 0;
for(int k = l + 1;k <= r;k++) {
if(count(sl.begin(), sl.end(), s[l]) && ok(s[k], s[l])) {
int cnt = 1;
if(s[l] == s[k] && s[l] == '?')
cnt = 4;
ans += solve(l + 1, k - 1) * cnt * solve(k + 1, r);
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> s;
int n = s.size();
memset(memo, -1, sizeof memo);
cout << solve(0, n - 1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
input:
??
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3528kb
input:
????
output:
32
result:
ok single line: '32'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
????????
output:
3584
result:
ok single line: '3584'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
]????]
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
?????[
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
([???]
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
??({?]
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
??({?]??
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
?[()?)()]]
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3636kb
input:
?()?????
output:
320
result:
ok single line: '320'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
?????()?
output:
320
result:
ok single line: '320'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
???([]){}???
output:
320
result:
ok single line: '320'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3744kb
input:
????????????????????
output:
17611882496
result:
ok single line: '17611882496'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
<{[{()}]}<>{}>{?()[]
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3600kb
input:
[<{}<><?[]>?[]{}<{}>
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3632kb
input:
()<{}{}><???[]>>[()]
output:
9
result:
ok single line: '9'
Test #17:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
([{?}}<??){<>}[?}<>]
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
{}(?(?()[]??]<>){[]?
output:
21
result:
ok single line: '21'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
<??>]??{{}[]}>>()?{}
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
{???{(({?><>?>})){}}
output:
8
result:
ok single line: '8'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
?<()[]?<{?>??>>())[]
output:
11
result:
ok single line: '11'
Test #22:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
?[()?)()][]{[?}>?]{?
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
{?(?>)<>>{}<?{}}?]{?
output:
1
result:
ok single line: '1'
Test #24:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
[?}[[???[??????]??>?
output:
34880
result:
ok single line: '34880'
Test #25:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
??<???????<>??[??]{?
output:
629760
result:
ok single line: '629760'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
?????????[?)?}?>[???
output:
889856
result:
ok single line: '889856'
Test #27:
score: 0
Accepted
time: 2ms
memory: 3700kb
input:
????????????}(??????
output:
275382272
result:
ok single line: '275382272'
Test #28:
score: 0
Accepted
time: 2ms
memory: 3636kb
input:
?[??]?{??)??????????
output:
8609792
result:
ok single line: '8609792'
Test #29:
score: 0
Accepted
time: 2ms
memory: 3588kb
input:
???????(??)??{?????>
output:
16621568
result:
ok single line: '16621568'
Test #30:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
????[]?[<???????????
output:
21446656
result:
ok single line: '21446656'
Test #31:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
???????}>??????)?)??
output:
4677632
result:
ok single line: '4677632'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
[??????(??????????{}
output:
41435136
result:
ok single line: '41435136'
Test #33:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
(?>?[???????????}???
output:
8740864
result:
ok single line: '8740864'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
()()(?
output:
1
result:
ok single line: '1'
Test #35:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
(??)
output:
5
result:
ok single line: '5'
Test #36:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
(<{}>??]
output:
1
result:
ok single line: '1'
Test #37:
score: 0
Accepted
time: 2ms
memory: 3672kb
input:
(?]]
output:
0
result:
ok single line: '0'