/*input
3
x))
*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define MNTO(x,y) x=min(x,y)
#define MXTO(x,y) x=max(x,y)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define ld long double
#define sz(x) (int)x.size()
#define pii pair<ll,ll>
#define pdd pair<ld,ld>
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
const int INF=0x3f3f3f3f;
const int maxn=100+5;
int pf[maxn],pm[maxn];
bool check(string s){
int n=sz(s);
int x=0;
int mn=INF;
REP1(i,n){
if(s[i-1]=='(') ++x;
else --x;
pf[i]=x;
MNTO(mn,pf[i]);
}
int r=0;
for(int i=n;i>=0;i--){
if(pf[i]<pf[n]){
r=i;
break;
}
}
if(pf[n]==0 and mn==0){
return true;
}
REP(i,n+2) pm[i]=0;
for(int i=r;i>=0;i--){
pm[i]=max(pm[i+1],pf[i]);
}
REP1(j,n){
if(pf[j-1]<0) break;
int mx=pm[j];
for(int i=max(r,j);i<=n;i++){
MXTO(mx,pf[i]);
if(mx>pf[j-1]*2){
break;
}
if((2*pf[j-1]-2*pf[i]+pf[n])==0){
return true;
}
}
}
return false;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n;
cin>>n;
if(n%2){
cout<<0;
return 0;
}
string s;
cin>>s;
vector<int> v;
REP(i,n){
if(s[i]=='x') v.pb(i);
}
int ans=0;
REP(i,(1<<sz(v))){
string tmp=s;
REP(j,sz(v)){
if(i&(1<<j)) s[v[j]]='(';
else s[v[j]]=')';
}
ans+=check(s);
s=tmp;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
328 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
328 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
19 ms |
212 KB |
Output is correct |
33 |
Correct |
5 ms |
320 KB |
Output is correct |
34 |
Correct |
345 ms |
300 KB |
Output is correct |
35 |
Correct |
20 ms |
320 KB |
Output is correct |
36 |
Correct |
42 ms |
212 KB |
Output is correct |
37 |
Correct |
144 ms |
300 KB |
Output is correct |
38 |
Correct |
961 ms |
296 KB |
Output is correct |
39 |
Correct |
20 ms |
212 KB |
Output is correct |
40 |
Correct |
477 ms |
300 KB |
Output is correct |
41 |
Correct |
692 ms |
332 KB |
Output is correct |
42 |
Correct |
692 ms |
300 KB |
Output is correct |
43 |
Correct |
305 ms |
332 KB |
Output is correct |
44 |
Correct |
34 ms |
296 KB |
Output is correct |
45 |
Correct |
754 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
328 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
19 ms |
212 KB |
Output is correct |
33 |
Correct |
5 ms |
320 KB |
Output is correct |
34 |
Correct |
345 ms |
300 KB |
Output is correct |
35 |
Correct |
20 ms |
320 KB |
Output is correct |
36 |
Correct |
42 ms |
212 KB |
Output is correct |
37 |
Correct |
144 ms |
300 KB |
Output is correct |
38 |
Correct |
961 ms |
296 KB |
Output is correct |
39 |
Correct |
20 ms |
212 KB |
Output is correct |
40 |
Correct |
477 ms |
300 KB |
Output is correct |
41 |
Correct |
692 ms |
332 KB |
Output is correct |
42 |
Correct |
692 ms |
300 KB |
Output is correct |
43 |
Correct |
305 ms |
332 KB |
Output is correct |
44 |
Correct |
34 ms |
296 KB |
Output is correct |
45 |
Correct |
754 ms |
300 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
316 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
328 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
19 ms |
212 KB |
Output is correct |
33 |
Correct |
5 ms |
320 KB |
Output is correct |
34 |
Correct |
345 ms |
300 KB |
Output is correct |
35 |
Correct |
20 ms |
320 KB |
Output is correct |
36 |
Correct |
42 ms |
212 KB |
Output is correct |
37 |
Correct |
144 ms |
300 KB |
Output is correct |
38 |
Correct |
961 ms |
296 KB |
Output is correct |
39 |
Correct |
20 ms |
212 KB |
Output is correct |
40 |
Correct |
477 ms |
300 KB |
Output is correct |
41 |
Correct |
692 ms |
332 KB |
Output is correct |
42 |
Correct |
692 ms |
300 KB |
Output is correct |
43 |
Correct |
305 ms |
332 KB |
Output is correct |
44 |
Correct |
34 ms |
296 KB |
Output is correct |
45 |
Correct |
754 ms |
300 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
316 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |