QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726430 | #2927. Bracket Pairing | zeyu# | AC ✓ | 1ms | 3864kb | C++23 | 2.7kb | 2024-11-09 00:23:23 | 2024-11-09 00:23:25 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif
const ll mod = 1e9 + 7;
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}
char c[8] = {'(', ')', '[', ']', '{', '}', '<', '>'};
map<char, int> id, val;
string s;
int n;
map<string, ll> memo;
//s[x], c[z]
ll dfs(string s){
if (memo.count(s)) return memo[s];
if (s.size() == 0) return 1;
if (val[s[0]] < 0) return 0;
ll ans = 0;
if (s[0] == '?'){
for (int i = 0; i < 4; i ++){
for (int j = 1; j < s.size(); j ++){
if (s[j] == '?' || (id[s[j]] == i && val[s[j]] == -1)) ans += dfs(s.substr(1, j - 1)) * dfs(s.substr(j + 1, n - 1 - j));
}
}
} else{
for (int j = 1; j < s.size(); j ++){
if (s[j] == '?' || (id[s[j]] == id[s[0]] && val[s[j]] == -1)) ans += dfs(s.substr(1, j - 1)) * dfs(s.substr(j + 1, n - 1 - j));
}
}
memo[s] = ans;
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
id['('] = 0; id[')'] = 0;
id['['] = 1; id[']'] = 1;
id['{'] = 2; id['}'] = 2;
id['<'] = 3; id['>'] = 3;
val['('] = 1; val[')'] = -1;
val['['] = 1; val[']'] = -1;
val['{'] = 1; val['}'] = -1;
val['<'] = 1; val['>'] = -1;
cin >> s; n = s.size();
ll ans = dfs(s);
cout << ans << '\n';
}
//hard case: ????????????????????
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
??
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
????
output:
32
result:
ok single line: '32'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
????????
output:
3584
result:
ok single line: '3584'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
]????]
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
?????[
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
([???]
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
??({?]
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
??({?]??
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
?[()?)()]]
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
?()?????
output:
320
result:
ok single line: '320'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
?????()?
output:
320
result:
ok single line: '320'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
???([]){}???
output:
320
result:
ok single line: '320'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
????????????????????
output:
17611882496
result:
ok single line: '17611882496'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
<{[{()}]}<>{}>{?()[]
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
[<{}<><?[]>?[]{}<{}>
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
()<{}{}><???[]>>[()]
output:
9
result:
ok single line: '9'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
([{?}}<??){<>}[?}<>]
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
{}(?(?()[]??]<>){[]?
output:
21
result:
ok single line: '21'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
<??>]??{{}[]}>>()?{}
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
{???{(({?><>?>})){}}
output:
8
result:
ok single line: '8'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
?<()[]?<{?>??>>())[]
output:
11
result:
ok single line: '11'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
?[()?)()][]{[?}>?]{?
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
{?(?>)<>>{}<?{}}?]{?
output:
1
result:
ok single line: '1'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
[?}[[???[??????]??>?
output:
34880
result:
ok single line: '34880'
Test #25:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
??<???????<>??[??]{?
output:
629760
result:
ok single line: '629760'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
?????????[?)?}?>[???
output:
889856
result:
ok single line: '889856'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
????????????}(??????
output:
275382272
result:
ok single line: '275382272'
Test #28:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
?[??]?{??)??????????
output:
8609792
result:
ok single line: '8609792'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
???????(??)??{?????>
output:
16621568
result:
ok single line: '16621568'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
????[]?[<???????????
output:
21446656
result:
ok single line: '21446656'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
???????}>??????)?)??
output:
4677632
result:
ok single line: '4677632'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
[??????(??????????{}
output:
41435136
result:
ok single line: '41435136'
Test #33:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
(?>?[???????????}???
output:
8740864
result:
ok single line: '8740864'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
()()(?
output:
1
result:
ok single line: '1'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
(??)
output:
5
result:
ok single line: '5'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
(<{}>??]
output:
1
result:
ok single line: '1'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
(?]]
output:
0
result:
ok single line: '0'