#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
LL check2(string s){
vector<int> psums(1,0);
for(int j = 0; j < s.size(); j++){
if(s[j] == '('){
psums.push_back(psums[psums.size() - 1] + 1);
} else {
psums.push_back(psums[psums.size() - 1] - 1);
}
}
int laste = psums.size() - 1;
while(laste > 0 && psums[laste - 1] >= psums[psums.size() - 1]){
laste--;
}
int lasts = 0;
while(lasts + 1 < psums.size() && psums[lasts + 1] >= psums[0]){
lasts++;
}
int a = psums[psums.size() - 1] / 2;
if(lasts == psums.size() - 1 && laste == 0){
return 1;
} else if(lasts == psums.size() - 1){
int maxv = 0;
for(int i = laste; i < psums.size(); i++){
maxv = max(maxv, psums[i] - psums[psums.size() - 1]);
}
for(int i = laste; i >= 0; i--){
if(psums[i] - psums[psums.size() - 1] <= maxv - a) return 1;
if(psums[i] - psums[psums.size() - 1] > 2 * maxv) return 0;
}
} else if(laste == 0){
int maxv = 0;
for(int i = 0; i <= lasts; i++){
maxv = max(maxv, psums[i]);
}
for(int i = lasts; i < psums.size(); i++){
if(psums[i] <= maxv + a) return 1;
if(psums[i] > 2 * maxv) return 0;
}
} else {
int maxl = psums[0];
int maxm = psums[lasts];
int maxr = psums[psums.size() - 1];
for(int i = 0; i <= lasts; i++){
maxl = max(maxl, psums[i]);
}
for(int i = lasts; i <= laste; i++){
maxm = max(maxm, psums[i]);
}
for(int i = laste; i < psums.size(); i++){
maxr = max(maxr, psums[i]);
}
return (maxm <= 2 * maxl && maxm <= 2 * (maxr - a));
}
return 0;
}
LL cnt(string s, int idx){
if(idx == s.size()){
return check2(s);
}
if(s[idx] != 'x'){
return cnt(s, idx + 1);
}
string s1 = s;
string s2 = s;
s1[idx] = '(';
s2[idx] = ')';
for(int z = idx + 1; z <= s.size(); z++){
if(z == s.size() || s[z] == 'x'){
return (cnt(s1, z) + cnt(s2, z)) % MOD;
}
}
}
int main(){
int n;
string s;
cin >> n >> s;
if(n % 2 == 1){
cout << 0 << '\n';
return 0;
}
cout << cnt(s, 0) << '\n';
}
Compilation message
securitygate.cpp: In function 'LL check2(std::__cxx11::string)':
securitygate.cpp:8:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < s.size(); j++){
~~^~~~~~~~~~
securitygate.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(lasts + 1 < psums.size() && psums[lasts + 1] >= psums[0]){
~~~~~~~~~~^~~~~~~~~~~~~~
securitygate.cpp:24:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(lasts == psums.size() - 1 && laste == 0){
~~~~~~^~~~~~~~~~~~~~~~~~~
securitygate.cpp:26:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} else if(lasts == psums.size() - 1){
~~~~~~^~~~~~~~~~~~~~~~~~~
securitygate.cpp:28:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = laste; i < psums.size(); i++){
~~^~~~~~~~~~~~~~
securitygate.cpp:40:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = lasts; i < psums.size(); i++){
~~^~~~~~~~~~~~~~
securitygate.cpp:54:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = laste; i < psums.size(); i++){
~~^~~~~~~~~~~~~~
securitygate.cpp: In function 'LL cnt(std::__cxx11::string, int)':
securitygate.cpp:63:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(idx == s.size()){
~~~~^~~~~~~~~~~
securitygate.cpp:73:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int z = idx + 1; z <= s.size(); z++){
~~^~~~~~~~~~~
securitygate.cpp:74:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(z == s.size() || s[z] == 'x'){
~~^~~~~~~~~~~
securitygate.cpp:78:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
4 |
Correct |
3 ms |
660 KB |
Output is correct |
5 |
Correct |
3 ms |
660 KB |
Output is correct |
6 |
Correct |
2 ms |
660 KB |
Output is correct |
7 |
Correct |
3 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
660 KB |
Output is correct |
9 |
Correct |
3 ms |
660 KB |
Output is correct |
10 |
Correct |
2 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
660 KB |
Output is correct |
12 |
Correct |
3 ms |
660 KB |
Output is correct |
13 |
Correct |
2 ms |
660 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
2 ms |
660 KB |
Output is correct |
16 |
Correct |
2 ms |
660 KB |
Output is correct |
17 |
Correct |
2 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
4 |
Correct |
3 ms |
660 KB |
Output is correct |
5 |
Correct |
3 ms |
660 KB |
Output is correct |
6 |
Correct |
2 ms |
660 KB |
Output is correct |
7 |
Correct |
3 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
660 KB |
Output is correct |
9 |
Correct |
3 ms |
660 KB |
Output is correct |
10 |
Correct |
2 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
660 KB |
Output is correct |
12 |
Correct |
3 ms |
660 KB |
Output is correct |
13 |
Correct |
2 ms |
660 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
2 ms |
660 KB |
Output is correct |
16 |
Correct |
2 ms |
660 KB |
Output is correct |
17 |
Correct |
2 ms |
660 KB |
Output is correct |
18 |
Correct |
2 ms |
660 KB |
Output is correct |
19 |
Correct |
2 ms |
660 KB |
Output is correct |
20 |
Correct |
5 ms |
660 KB |
Output is correct |
21 |
Correct |
8 ms |
660 KB |
Output is correct |
22 |
Correct |
9 ms |
660 KB |
Output is correct |
23 |
Correct |
4 ms |
660 KB |
Output is correct |
24 |
Correct |
9 ms |
660 KB |
Output is correct |
25 |
Correct |
3 ms |
660 KB |
Output is correct |
26 |
Correct |
4 ms |
660 KB |
Output is correct |
27 |
Correct |
7 ms |
660 KB |
Output is correct |
28 |
Correct |
5 ms |
660 KB |
Output is correct |
29 |
Correct |
4 ms |
660 KB |
Output is correct |
30 |
Correct |
3 ms |
660 KB |
Output is correct |
31 |
Correct |
9 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
4 |
Correct |
3 ms |
660 KB |
Output is correct |
5 |
Correct |
3 ms |
660 KB |
Output is correct |
6 |
Correct |
2 ms |
660 KB |
Output is correct |
7 |
Correct |
3 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
660 KB |
Output is correct |
9 |
Correct |
3 ms |
660 KB |
Output is correct |
10 |
Correct |
2 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
660 KB |
Output is correct |
12 |
Correct |
3 ms |
660 KB |
Output is correct |
13 |
Correct |
2 ms |
660 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
2 ms |
660 KB |
Output is correct |
16 |
Correct |
2 ms |
660 KB |
Output is correct |
17 |
Correct |
2 ms |
660 KB |
Output is correct |
18 |
Correct |
2 ms |
660 KB |
Output is correct |
19 |
Correct |
2 ms |
660 KB |
Output is correct |
20 |
Correct |
5 ms |
660 KB |
Output is correct |
21 |
Correct |
8 ms |
660 KB |
Output is correct |
22 |
Correct |
9 ms |
660 KB |
Output is correct |
23 |
Correct |
4 ms |
660 KB |
Output is correct |
24 |
Correct |
9 ms |
660 KB |
Output is correct |
25 |
Correct |
3 ms |
660 KB |
Output is correct |
26 |
Correct |
4 ms |
660 KB |
Output is correct |
27 |
Correct |
7 ms |
660 KB |
Output is correct |
28 |
Correct |
5 ms |
660 KB |
Output is correct |
29 |
Correct |
4 ms |
660 KB |
Output is correct |
30 |
Correct |
3 ms |
660 KB |
Output is correct |
31 |
Correct |
9 ms |
660 KB |
Output is correct |
32 |
Correct |
50 ms |
660 KB |
Output is correct |
33 |
Correct |
22 ms |
660 KB |
Output is correct |
34 |
Correct |
985 ms |
660 KB |
Output is correct |
35 |
Correct |
53 ms |
660 KB |
Output is correct |
36 |
Correct |
98 ms |
660 KB |
Output is correct |
37 |
Correct |
363 ms |
660 KB |
Output is correct |
38 |
Correct |
1931 ms |
660 KB |
Output is correct |
39 |
Correct |
57 ms |
660 KB |
Output is correct |
40 |
Correct |
1522 ms |
660 KB |
Output is correct |
41 |
Correct |
1519 ms |
660 KB |
Output is correct |
42 |
Correct |
1532 ms |
660 KB |
Output is correct |
43 |
Correct |
881 ms |
660 KB |
Output is correct |
44 |
Correct |
173 ms |
660 KB |
Output is correct |
45 |
Correct |
1836 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
4 |
Correct |
3 ms |
660 KB |
Output is correct |
5 |
Correct |
3 ms |
660 KB |
Output is correct |
6 |
Correct |
2 ms |
660 KB |
Output is correct |
7 |
Correct |
3 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
660 KB |
Output is correct |
9 |
Correct |
3 ms |
660 KB |
Output is correct |
10 |
Correct |
2 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
660 KB |
Output is correct |
12 |
Correct |
3 ms |
660 KB |
Output is correct |
13 |
Correct |
2 ms |
660 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
2 ms |
660 KB |
Output is correct |
16 |
Correct |
2 ms |
660 KB |
Output is correct |
17 |
Correct |
2 ms |
660 KB |
Output is correct |
18 |
Correct |
2 ms |
660 KB |
Output is correct |
19 |
Correct |
2 ms |
660 KB |
Output is correct |
20 |
Correct |
5 ms |
660 KB |
Output is correct |
21 |
Correct |
8 ms |
660 KB |
Output is correct |
22 |
Correct |
9 ms |
660 KB |
Output is correct |
23 |
Correct |
4 ms |
660 KB |
Output is correct |
24 |
Correct |
9 ms |
660 KB |
Output is correct |
25 |
Correct |
3 ms |
660 KB |
Output is correct |
26 |
Correct |
4 ms |
660 KB |
Output is correct |
27 |
Correct |
7 ms |
660 KB |
Output is correct |
28 |
Correct |
5 ms |
660 KB |
Output is correct |
29 |
Correct |
4 ms |
660 KB |
Output is correct |
30 |
Correct |
3 ms |
660 KB |
Output is correct |
31 |
Correct |
9 ms |
660 KB |
Output is correct |
32 |
Correct |
50 ms |
660 KB |
Output is correct |
33 |
Correct |
22 ms |
660 KB |
Output is correct |
34 |
Correct |
985 ms |
660 KB |
Output is correct |
35 |
Correct |
53 ms |
660 KB |
Output is correct |
36 |
Correct |
98 ms |
660 KB |
Output is correct |
37 |
Correct |
363 ms |
660 KB |
Output is correct |
38 |
Correct |
1931 ms |
660 KB |
Output is correct |
39 |
Correct |
57 ms |
660 KB |
Output is correct |
40 |
Correct |
1522 ms |
660 KB |
Output is correct |
41 |
Correct |
1519 ms |
660 KB |
Output is correct |
42 |
Correct |
1532 ms |
660 KB |
Output is correct |
43 |
Correct |
881 ms |
660 KB |
Output is correct |
44 |
Correct |
173 ms |
660 KB |
Output is correct |
45 |
Correct |
1836 ms |
660 KB |
Output is correct |
46 |
Correct |
3 ms |
660 KB |
Output is correct |
47 |
Correct |
2 ms |
668 KB |
Output is correct |
48 |
Correct |
2 ms |
668 KB |
Output is correct |
49 |
Execution timed out |
5007 ms |
668 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
4 |
Correct |
3 ms |
660 KB |
Output is correct |
5 |
Correct |
3 ms |
660 KB |
Output is correct |
6 |
Correct |
2 ms |
660 KB |
Output is correct |
7 |
Correct |
3 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
660 KB |
Output is correct |
9 |
Correct |
3 ms |
660 KB |
Output is correct |
10 |
Correct |
2 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
660 KB |
Output is correct |
12 |
Correct |
3 ms |
660 KB |
Output is correct |
13 |
Correct |
2 ms |
660 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
2 ms |
660 KB |
Output is correct |
16 |
Correct |
2 ms |
660 KB |
Output is correct |
17 |
Correct |
2 ms |
660 KB |
Output is correct |
18 |
Correct |
2 ms |
660 KB |
Output is correct |
19 |
Correct |
2 ms |
660 KB |
Output is correct |
20 |
Correct |
5 ms |
660 KB |
Output is correct |
21 |
Correct |
8 ms |
660 KB |
Output is correct |
22 |
Correct |
9 ms |
660 KB |
Output is correct |
23 |
Correct |
4 ms |
660 KB |
Output is correct |
24 |
Correct |
9 ms |
660 KB |
Output is correct |
25 |
Correct |
3 ms |
660 KB |
Output is correct |
26 |
Correct |
4 ms |
660 KB |
Output is correct |
27 |
Correct |
7 ms |
660 KB |
Output is correct |
28 |
Correct |
5 ms |
660 KB |
Output is correct |
29 |
Correct |
4 ms |
660 KB |
Output is correct |
30 |
Correct |
3 ms |
660 KB |
Output is correct |
31 |
Correct |
9 ms |
660 KB |
Output is correct |
32 |
Correct |
50 ms |
660 KB |
Output is correct |
33 |
Correct |
22 ms |
660 KB |
Output is correct |
34 |
Correct |
985 ms |
660 KB |
Output is correct |
35 |
Correct |
53 ms |
660 KB |
Output is correct |
36 |
Correct |
98 ms |
660 KB |
Output is correct |
37 |
Correct |
363 ms |
660 KB |
Output is correct |
38 |
Correct |
1931 ms |
660 KB |
Output is correct |
39 |
Correct |
57 ms |
660 KB |
Output is correct |
40 |
Correct |
1522 ms |
660 KB |
Output is correct |
41 |
Correct |
1519 ms |
660 KB |
Output is correct |
42 |
Correct |
1532 ms |
660 KB |
Output is correct |
43 |
Correct |
881 ms |
660 KB |
Output is correct |
44 |
Correct |
173 ms |
660 KB |
Output is correct |
45 |
Correct |
1836 ms |
660 KB |
Output is correct |
46 |
Correct |
3 ms |
660 KB |
Output is correct |
47 |
Correct |
2 ms |
668 KB |
Output is correct |
48 |
Correct |
2 ms |
668 KB |
Output is correct |
49 |
Execution timed out |
5007 ms |
668 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |