#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
LL check(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--;
}
map<int,vector<int> > endlists;
map<int,vector<int> > psumlists;
for(int j = laste; j <= psums.size() - 1; j++){
endlists[psums[j]].push_back(j);
}
for(int j = 0; j <= psums.size() - 1; j++){
psumlists[psums[j]].push_back(j);
}
int a = psums[psums.size() - 1] / 2;
for(int j = 0; j < psums.size(); j++){
if(psums[j] < 0) break;
int need = psums[j] + a;
vector<int>& z = endlists[need];
int idx = lower_bound(z.begin(), z.end(), j) - z.begin();
if(idx >= z.size()) continue;
int e = z[idx];
// check if all elements in [j,e] are <=
vector<int>& w = psumlists[2 * psums[j] + 1];
int idx2 = lower_bound(w.begin(), w.end(), j) - w.begin();
if(idx2 < w.size() && w[idx2] <= e){
continue;
}
return 1;
}
return 0;
}
LL cnt(string s, int idx){
if(idx == s.size()) return check(s);
if(s[idx] != 'x'){
return cnt(s, idx + 1);
}
string s1 = s;
string s2 = s;
s1[idx] = '(';
s2[idx] = ')';
return (cnt(s1, idx + 1) + cnt(s2, idx + 1)) % 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 check(std::__cxx11::string)':
securitygate.cpp:9:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < s.size(); j++){
~~^~~~~~~~~~
securitygate.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = laste; j <= psums.size() - 1; j++){
~~^~~~~~~~~~~~~~~~~~~
securitygate.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j <= psums.size() - 1; j++){
~~^~~~~~~~~~~~~~~~~~~
securitygate.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < psums.size(); j++){
~~^~~~~~~~~~~~~~
securitygate.cpp:34:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(idx >= z.size()) continue;
~~~~^~~~~~~~~~~
securitygate.cpp:39:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(idx2 < w.size() && w[idx2] <= e){
~~~~~^~~~~~~~~~
securitygate.cpp: In function 'LL cnt(std::__cxx11::string, int)':
securitygate.cpp:48:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(idx == s.size()) return check(s);
~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
688 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
3 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
688 KB |
Output is correct |
9 |
Correct |
3 ms |
688 KB |
Output is correct |
10 |
Correct |
2 ms |
688 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
688 KB |
Output is correct |
13 |
Correct |
3 ms |
688 KB |
Output is correct |
14 |
Correct |
3 ms |
688 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
4 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
688 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
3 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
688 KB |
Output is correct |
9 |
Correct |
3 ms |
688 KB |
Output is correct |
10 |
Correct |
2 ms |
688 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
688 KB |
Output is correct |
13 |
Correct |
3 ms |
688 KB |
Output is correct |
14 |
Correct |
3 ms |
688 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
4 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
4 ms |
748 KB |
Output is correct |
20 |
Correct |
22 ms |
748 KB |
Output is correct |
21 |
Correct |
62 ms |
748 KB |
Output is correct |
22 |
Correct |
32 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
37 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
756 KB |
Output is correct |
26 |
Correct |
11 ms |
756 KB |
Output is correct |
27 |
Correct |
74 ms |
756 KB |
Output is correct |
28 |
Correct |
18 ms |
756 KB |
Output is correct |
29 |
Correct |
8 ms |
756 KB |
Output is correct |
30 |
Correct |
4 ms |
756 KB |
Output is correct |
31 |
Correct |
37 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
688 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
3 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
688 KB |
Output is correct |
9 |
Correct |
3 ms |
688 KB |
Output is correct |
10 |
Correct |
2 ms |
688 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
688 KB |
Output is correct |
13 |
Correct |
3 ms |
688 KB |
Output is correct |
14 |
Correct |
3 ms |
688 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
4 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
4 ms |
748 KB |
Output is correct |
20 |
Correct |
22 ms |
748 KB |
Output is correct |
21 |
Correct |
62 ms |
748 KB |
Output is correct |
22 |
Correct |
32 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
37 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
756 KB |
Output is correct |
26 |
Correct |
11 ms |
756 KB |
Output is correct |
27 |
Correct |
74 ms |
756 KB |
Output is correct |
28 |
Correct |
18 ms |
756 KB |
Output is correct |
29 |
Correct |
8 ms |
756 KB |
Output is correct |
30 |
Correct |
4 ms |
756 KB |
Output is correct |
31 |
Correct |
37 ms |
756 KB |
Output is correct |
32 |
Correct |
178 ms |
756 KB |
Output is correct |
33 |
Correct |
43 ms |
756 KB |
Output is correct |
34 |
Execution timed out |
5070 ms |
756 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
688 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
3 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
688 KB |
Output is correct |
9 |
Correct |
3 ms |
688 KB |
Output is correct |
10 |
Correct |
2 ms |
688 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
688 KB |
Output is correct |
13 |
Correct |
3 ms |
688 KB |
Output is correct |
14 |
Correct |
3 ms |
688 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
4 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
4 ms |
748 KB |
Output is correct |
20 |
Correct |
22 ms |
748 KB |
Output is correct |
21 |
Correct |
62 ms |
748 KB |
Output is correct |
22 |
Correct |
32 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
37 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
756 KB |
Output is correct |
26 |
Correct |
11 ms |
756 KB |
Output is correct |
27 |
Correct |
74 ms |
756 KB |
Output is correct |
28 |
Correct |
18 ms |
756 KB |
Output is correct |
29 |
Correct |
8 ms |
756 KB |
Output is correct |
30 |
Correct |
4 ms |
756 KB |
Output is correct |
31 |
Correct |
37 ms |
756 KB |
Output is correct |
32 |
Correct |
178 ms |
756 KB |
Output is correct |
33 |
Correct |
43 ms |
756 KB |
Output is correct |
34 |
Execution timed out |
5070 ms |
756 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
688 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
3 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
688 KB |
Output is correct |
9 |
Correct |
3 ms |
688 KB |
Output is correct |
10 |
Correct |
2 ms |
688 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
688 KB |
Output is correct |
13 |
Correct |
3 ms |
688 KB |
Output is correct |
14 |
Correct |
3 ms |
688 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
4 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
4 ms |
748 KB |
Output is correct |
20 |
Correct |
22 ms |
748 KB |
Output is correct |
21 |
Correct |
62 ms |
748 KB |
Output is correct |
22 |
Correct |
32 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
37 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
756 KB |
Output is correct |
26 |
Correct |
11 ms |
756 KB |
Output is correct |
27 |
Correct |
74 ms |
756 KB |
Output is correct |
28 |
Correct |
18 ms |
756 KB |
Output is correct |
29 |
Correct |
8 ms |
756 KB |
Output is correct |
30 |
Correct |
4 ms |
756 KB |
Output is correct |
31 |
Correct |
37 ms |
756 KB |
Output is correct |
32 |
Correct |
178 ms |
756 KB |
Output is correct |
33 |
Correct |
43 ms |
756 KB |
Output is correct |
34 |
Execution timed out |
5070 ms |
756 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |