#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int INF = 1e9 + 100;
char a[303], b[303];
int S[303], pos[606], pos2[606];
int ok2(int n, int l, int r){
for (int i=l+1;i<=r;i++) b[i] = ((b[i]=='(')?')':'(');
printf("ok2 -> %s\n", b+1);
for (int i=1;i<=n;i++) S[i] = S[i-1] + ((b[i]=='(')?1:-1);
return S[n]==0;
}
int ok(int n){
int flag2 = 1;
for (int i=1;i<=n;i++){
S[i] = S[i-1] + ((b[i]=='(')?1:-1);
if (S[i] < 0) flag2 = 0;
}
if (S[n]==0 && flag2){
return 1;
}
if (S[n] < 0){
for (int i=1;i<=n;i++) b[i] = ((b[i]=='(')?')':'(');
reverse(b+1, b+n+1);
return ok(n);
}
int lim = n, flag = 1;
for (int i=1;i<=n;i++) if (S[i] < 0) {lim = i-1; break;}
fill(pos, pos+n*2+2, INF);
fill(pos2, pos2+n*2+2, INF);
for (int i=n;i>=0;i--){
if (i<=lim){
int r = pos2[S[i]+(S[n]>>1)];
if (r < pos[S[i]<<1|1]){
// printf("ok %s -> flip %d %d\n", b+1, i, r);
// assert(ok2(n, i, r));
return 1;
}
}
if (S[i] < S[n]) flag = 0;
pos[S[i]] = i;
if (flag) pos2[S[i]] = i;
}
return 0;
}
int main(){
int n;
scanf("%d", &n);
scanf("%s", a+1);
for (int i=1;i<=n;i++) b[i] = a[i];
if (n%2==1){printf("0\n"); return 0;}
int cnt = 0;
for (int i=1;i<=n;i++) if (a[i]=='x') cnt++;
if (cnt > 20) return 0;
int ans = 0;
for (int z=0;z<(1<<cnt);z++){
for (int i=1;i<=n;i++) b[i] = a[i];
for (int i=1,j=0;i<=n;i++) if (a[i]=='x'){
if (z&(1<<j)) b[i] = ')';
else b[i] = '(';
j++;
}
if (ok(n)) ans++;
// printf("%s -> %d\n", b+1, ans);
}
printf("%d\n", ans);
}
Compilation message
securitygate.cpp: In function 'int main()':
securitygate.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
securitygate.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%s", a+1);
| ~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
284 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
5 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
3 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
284 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
5 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
3 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
10 ms |
312 KB |
Output is correct |
33 |
Correct |
3 ms |
212 KB |
Output is correct |
34 |
Correct |
272 ms |
288 KB |
Output is correct |
35 |
Correct |
9 ms |
212 KB |
Output is correct |
36 |
Correct |
49 ms |
284 KB |
Output is correct |
37 |
Correct |
213 ms |
284 KB |
Output is correct |
38 |
Correct |
891 ms |
288 KB |
Output is correct |
39 |
Correct |
9 ms |
212 KB |
Output is correct |
40 |
Correct |
804 ms |
288 KB |
Output is correct |
41 |
Correct |
622 ms |
292 KB |
Output is correct |
42 |
Correct |
829 ms |
284 KB |
Output is correct |
43 |
Correct |
409 ms |
288 KB |
Output is correct |
44 |
Correct |
41 ms |
212 KB |
Output is correct |
45 |
Correct |
800 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
284 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
5 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
3 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
10 ms |
312 KB |
Output is correct |
33 |
Correct |
3 ms |
212 KB |
Output is correct |
34 |
Correct |
272 ms |
288 KB |
Output is correct |
35 |
Correct |
9 ms |
212 KB |
Output is correct |
36 |
Correct |
49 ms |
284 KB |
Output is correct |
37 |
Correct |
213 ms |
284 KB |
Output is correct |
38 |
Correct |
891 ms |
288 KB |
Output is correct |
39 |
Correct |
9 ms |
212 KB |
Output is correct |
40 |
Correct |
804 ms |
288 KB |
Output is correct |
41 |
Correct |
622 ms |
292 KB |
Output is correct |
42 |
Correct |
829 ms |
284 KB |
Output is correct |
43 |
Correct |
409 ms |
288 KB |
Output is correct |
44 |
Correct |
41 ms |
212 KB |
Output is correct |
45 |
Correct |
800 ms |
292 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
284 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
5 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
3 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
10 ms |
312 KB |
Output is correct |
33 |
Correct |
3 ms |
212 KB |
Output is correct |
34 |
Correct |
272 ms |
288 KB |
Output is correct |
35 |
Correct |
9 ms |
212 KB |
Output is correct |
36 |
Correct |
49 ms |
284 KB |
Output is correct |
37 |
Correct |
213 ms |
284 KB |
Output is correct |
38 |
Correct |
891 ms |
288 KB |
Output is correct |
39 |
Correct |
9 ms |
212 KB |
Output is correct |
40 |
Correct |
804 ms |
288 KB |
Output is correct |
41 |
Correct |
622 ms |
292 KB |
Output is correct |
42 |
Correct |
829 ms |
284 KB |
Output is correct |
43 |
Correct |
409 ms |
288 KB |
Output is correct |
44 |
Correct |
41 ms |
212 KB |
Output is correct |
45 |
Correct |
800 ms |
292 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |