#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=310, inf=2e9;
int n;
char S[MX], R[MX], T[MX];
bool valid(){
int cnt=0, mn=0;
for(int i=1; i<=n; i++){
cnt+=T[i]=='(' ? 1 : -1;
mn=min(mn, cnt);
}
return cnt==0 && mn>=0;
}
bool solve(){
// cout<<(R+1)<<'\n';
for(int i=1; i<=n; i++) T[i]=R[i];
if(valid()) return true;
for(int i=1; i<=n; i++)
for(int j=i; j<=n; j++){
for(int k=1; k<=n; k++)
T[k]=R[k];
for(int k=i; k<=j; k++){
T[k]=T[k]==')' ? '(' : ')';
}
if(valid()) return true;
}
return false;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>(S+1);
vector<int> P;
for(int i=1; i<=n; i++) if(S[i]=='x') P.push_back(i);
int ans=0;
if(P.size()==0U) ans+=solve();
for(int i=0; i<(1<<(int)P.size()); i++){
for(int j=1; j<=n; j++){
R[j]=S[j];
}
for(int j=0; j<(int)P.size(); j++)
if(i&(1<<j)) R[P[j]]='(';
else R[P[j]]=')';
ans+=solve();
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
392 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
4 ms |
408 KB |
Output is correct |
7 |
Correct |
3 ms |
408 KB |
Output is correct |
8 |
Correct |
14 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
28 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
548 KB |
Output is correct |
13 |
Correct |
8 ms |
548 KB |
Output is correct |
14 |
Correct |
4 ms |
548 KB |
Output is correct |
15 |
Correct |
5 ms |
548 KB |
Output is correct |
16 |
Correct |
3 ms |
548 KB |
Output is correct |
17 |
Correct |
9 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
392 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
4 ms |
408 KB |
Output is correct |
7 |
Correct |
3 ms |
408 KB |
Output is correct |
8 |
Correct |
14 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
28 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
548 KB |
Output is correct |
13 |
Correct |
8 ms |
548 KB |
Output is correct |
14 |
Correct |
4 ms |
548 KB |
Output is correct |
15 |
Correct |
5 ms |
548 KB |
Output is correct |
16 |
Correct |
3 ms |
548 KB |
Output is correct |
17 |
Correct |
9 ms |
548 KB |
Output is correct |
18 |
Correct |
13 ms |
548 KB |
Output is correct |
19 |
Correct |
408 ms |
672 KB |
Output is correct |
20 |
Correct |
74 ms |
672 KB |
Output is correct |
21 |
Correct |
3824 ms |
672 KB |
Output is correct |
22 |
Correct |
1896 ms |
672 KB |
Output is correct |
23 |
Correct |
803 ms |
672 KB |
Output is correct |
24 |
Execution timed out |
5033 ms |
672 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
392 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
4 ms |
408 KB |
Output is correct |
7 |
Correct |
3 ms |
408 KB |
Output is correct |
8 |
Correct |
14 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
28 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
548 KB |
Output is correct |
13 |
Correct |
8 ms |
548 KB |
Output is correct |
14 |
Correct |
4 ms |
548 KB |
Output is correct |
15 |
Correct |
5 ms |
548 KB |
Output is correct |
16 |
Correct |
3 ms |
548 KB |
Output is correct |
17 |
Correct |
9 ms |
548 KB |
Output is correct |
18 |
Correct |
13 ms |
548 KB |
Output is correct |
19 |
Correct |
408 ms |
672 KB |
Output is correct |
20 |
Correct |
74 ms |
672 KB |
Output is correct |
21 |
Correct |
3824 ms |
672 KB |
Output is correct |
22 |
Correct |
1896 ms |
672 KB |
Output is correct |
23 |
Correct |
803 ms |
672 KB |
Output is correct |
24 |
Execution timed out |
5033 ms |
672 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
392 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
4 ms |
408 KB |
Output is correct |
7 |
Correct |
3 ms |
408 KB |
Output is correct |
8 |
Correct |
14 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
28 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
548 KB |
Output is correct |
13 |
Correct |
8 ms |
548 KB |
Output is correct |
14 |
Correct |
4 ms |
548 KB |
Output is correct |
15 |
Correct |
5 ms |
548 KB |
Output is correct |
16 |
Correct |
3 ms |
548 KB |
Output is correct |
17 |
Correct |
9 ms |
548 KB |
Output is correct |
18 |
Correct |
13 ms |
548 KB |
Output is correct |
19 |
Correct |
408 ms |
672 KB |
Output is correct |
20 |
Correct |
74 ms |
672 KB |
Output is correct |
21 |
Correct |
3824 ms |
672 KB |
Output is correct |
22 |
Correct |
1896 ms |
672 KB |
Output is correct |
23 |
Correct |
803 ms |
672 KB |
Output is correct |
24 |
Execution timed out |
5033 ms |
672 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
392 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
4 ms |
408 KB |
Output is correct |
7 |
Correct |
3 ms |
408 KB |
Output is correct |
8 |
Correct |
14 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
28 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
548 KB |
Output is correct |
13 |
Correct |
8 ms |
548 KB |
Output is correct |
14 |
Correct |
4 ms |
548 KB |
Output is correct |
15 |
Correct |
5 ms |
548 KB |
Output is correct |
16 |
Correct |
3 ms |
548 KB |
Output is correct |
17 |
Correct |
9 ms |
548 KB |
Output is correct |
18 |
Correct |
13 ms |
548 KB |
Output is correct |
19 |
Correct |
408 ms |
672 KB |
Output is correct |
20 |
Correct |
74 ms |
672 KB |
Output is correct |
21 |
Correct |
3824 ms |
672 KB |
Output is correct |
22 |
Correct |
1896 ms |
672 KB |
Output is correct |
23 |
Correct |
803 ms |
672 KB |
Output is correct |
24 |
Execution timed out |
5033 ms |
672 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |