# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57721 | 2018-07-15T22:13:53 Z | ksun48 | Security Gate (JOI18_security_gate) | C++14 | 5000 ms | 740 KB |
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL MOD = 1000000007; const int MAXN = 110; 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--; } vector<int> endlists[2 * MAXN]; vector<int> psumlists[2 * MAXN]; int ecuridx[2 * MAXN]; int pcuridx[2 * MAXN]; for(int j = laste; j <= psums.size() - 1; j++){ endlists[MAXN + psums[j]].push_back(j); ecuridx[MAXN + psums[j]] = 0; } for(int j = 0; j <= psums.size() - 1; j++){ psumlists[MAXN + psums[j]].push_back(j); pcuridx[MAXN + psums[j]] = 0; } 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[MAXN + need]; int idx = ecuridx[MAXN + need]; if(idx < z.size()){ int e = z[idx]; // check if all elements in [j,e] are <= vector<int>& w = psumlists[MAXN + 2 * psums[j] + 1]; int idx2 = pcuridx[MAXN + 2 * psums[j] + 1]; if(idx2 < w.size() && w[idx2] <= e){ } else { return 1; } } if(j >= laste){ ecuridx[MAXN + psums[j]]++; } pcuridx[MAXN + psums[j]]++; } 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] = ')'; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 472 KB | Output is correct |
3 | Correct | 3 ms | 524 KB | Output is correct |
4 | Correct | 2 ms | 524 KB | Output is correct |
5 | Correct | 2 ms | 524 KB | Output is correct |
6 | Correct | 3 ms | 524 KB | Output is correct |
7 | Correct | 2 ms | 552 KB | Output is correct |
8 | Correct | 2 ms | 568 KB | Output is correct |
9 | Correct | 2 ms | 612 KB | Output is correct |
10 | Correct | 2 ms | 612 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 2 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 3 ms | 612 KB | Output is correct |
15 | Correct | 3 ms | 612 KB | Output is correct |
16 | Correct | 2 ms | 612 KB | Output is correct |
17 | Correct | 2 ms | 612 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 472 KB | Output is correct |
3 | Correct | 3 ms | 524 KB | Output is correct |
4 | Correct | 2 ms | 524 KB | Output is correct |
5 | Correct | 2 ms | 524 KB | Output is correct |
6 | Correct | 3 ms | 524 KB | Output is correct |
7 | Correct | 2 ms | 552 KB | Output is correct |
8 | Correct | 2 ms | 568 KB | Output is correct |
9 | Correct | 2 ms | 612 KB | Output is correct |
10 | Correct | 2 ms | 612 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 2 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 3 ms | 612 KB | Output is correct |
15 | Correct | 3 ms | 612 KB | Output is correct |
16 | Correct | 2 ms | 612 KB | Output is correct |
17 | Correct | 2 ms | 612 KB | Output is correct |
18 | Correct | 3 ms | 612 KB | Output is correct |
19 | Correct | 5 ms | 612 KB | Output is correct |
20 | Correct | 16 ms | 612 KB | Output is correct |
21 | Correct | 25 ms | 612 KB | Output is correct |
22 | Correct | 26 ms | 612 KB | Output is correct |
23 | Correct | 6 ms | 612 KB | Output is correct |
24 | Correct | 29 ms | 740 KB | Output is correct |
25 | Correct | 5 ms | 740 KB | Output is correct |
26 | Correct | 12 ms | 740 KB | Output is correct |
27 | Correct | 33 ms | 740 KB | Output is correct |
28 | Correct | 17 ms | 740 KB | Output is correct |
29 | Correct | 7 ms | 740 KB | Output is correct |
30 | Correct | 3 ms | 740 KB | Output is correct |
31 | Correct | 27 ms | 740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 472 KB | Output is correct |
3 | Correct | 3 ms | 524 KB | Output is correct |
4 | Correct | 2 ms | 524 KB | Output is correct |
5 | Correct | 2 ms | 524 KB | Output is correct |
6 | Correct | 3 ms | 524 KB | Output is correct |
7 | Correct | 2 ms | 552 KB | Output is correct |
8 | Correct | 2 ms | 568 KB | Output is correct |
9 | Correct | 2 ms | 612 KB | Output is correct |
10 | Correct | 2 ms | 612 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 2 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 3 ms | 612 KB | Output is correct |
15 | Correct | 3 ms | 612 KB | Output is correct |
16 | Correct | 2 ms | 612 KB | Output is correct |
17 | Correct | 2 ms | 612 KB | Output is correct |
18 | Correct | 3 ms | 612 KB | Output is correct |
19 | Correct | 5 ms | 612 KB | Output is correct |
20 | Correct | 16 ms | 612 KB | Output is correct |
21 | Correct | 25 ms | 612 KB | Output is correct |
22 | Correct | 26 ms | 612 KB | Output is correct |
23 | Correct | 6 ms | 612 KB | Output is correct |
24 | Correct | 29 ms | 740 KB | Output is correct |
25 | Correct | 5 ms | 740 KB | Output is correct |
26 | Correct | 12 ms | 740 KB | Output is correct |
27 | Correct | 33 ms | 740 KB | Output is correct |
28 | Correct | 17 ms | 740 KB | Output is correct |
29 | Correct | 7 ms | 740 KB | Output is correct |
30 | Correct | 3 ms | 740 KB | Output is correct |
31 | Correct | 27 ms | 740 KB | Output is correct |
32 | Correct | 236 ms | 740 KB | Output is correct |
33 | Correct | 56 ms | 740 KB | Output is correct |
34 | Correct | 4527 ms | 740 KB | Output is correct |
35 | Correct | 180 ms | 740 KB | Output is correct |
36 | Correct | 375 ms | 740 KB | Output is correct |
37 | Correct | 1781 ms | 740 KB | Output is correct |
38 | Execution timed out | 5090 ms | 740 KB | Time limit exceeded |
39 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 472 KB | Output is correct |
3 | Correct | 3 ms | 524 KB | Output is correct |
4 | Correct | 2 ms | 524 KB | Output is correct |
5 | Correct | 2 ms | 524 KB | Output is correct |
6 | Correct | 3 ms | 524 KB | Output is correct |
7 | Correct | 2 ms | 552 KB | Output is correct |
8 | Correct | 2 ms | 568 KB | Output is correct |
9 | Correct | 2 ms | 612 KB | Output is correct |
10 | Correct | 2 ms | 612 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 2 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 3 ms | 612 KB | Output is correct |
15 | Correct | 3 ms | 612 KB | Output is correct |
16 | Correct | 2 ms | 612 KB | Output is correct |
17 | Correct | 2 ms | 612 KB | Output is correct |
18 | Correct | 3 ms | 612 KB | Output is correct |
19 | Correct | 5 ms | 612 KB | Output is correct |
20 | Correct | 16 ms | 612 KB | Output is correct |
21 | Correct | 25 ms | 612 KB | Output is correct |
22 | Correct | 26 ms | 612 KB | Output is correct |
23 | Correct | 6 ms | 612 KB | Output is correct |
24 | Correct | 29 ms | 740 KB | Output is correct |
25 | Correct | 5 ms | 740 KB | Output is correct |
26 | Correct | 12 ms | 740 KB | Output is correct |
27 | Correct | 33 ms | 740 KB | Output is correct |
28 | Correct | 17 ms | 740 KB | Output is correct |
29 | Correct | 7 ms | 740 KB | Output is correct |
30 | Correct | 3 ms | 740 KB | Output is correct |
31 | Correct | 27 ms | 740 KB | Output is correct |
32 | Correct | 236 ms | 740 KB | Output is correct |
33 | Correct | 56 ms | 740 KB | Output is correct |
34 | Correct | 4527 ms | 740 KB | Output is correct |
35 | Correct | 180 ms | 740 KB | Output is correct |
36 | Correct | 375 ms | 740 KB | Output is correct |
37 | Correct | 1781 ms | 740 KB | Output is correct |
38 | Execution timed out | 5090 ms | 740 KB | Time limit exceeded |
39 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 472 KB | Output is correct |
3 | Correct | 3 ms | 524 KB | Output is correct |
4 | Correct | 2 ms | 524 KB | Output is correct |
5 | Correct | 2 ms | 524 KB | Output is correct |
6 | Correct | 3 ms | 524 KB | Output is correct |
7 | Correct | 2 ms | 552 KB | Output is correct |
8 | Correct | 2 ms | 568 KB | Output is correct |
9 | Correct | 2 ms | 612 KB | Output is correct |
10 | Correct | 2 ms | 612 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 2 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 3 ms | 612 KB | Output is correct |
15 | Correct | 3 ms | 612 KB | Output is correct |
16 | Correct | 2 ms | 612 KB | Output is correct |
17 | Correct | 2 ms | 612 KB | Output is correct |
18 | Correct | 3 ms | 612 KB | Output is correct |
19 | Correct | 5 ms | 612 KB | Output is correct |
20 | Correct | 16 ms | 612 KB | Output is correct |
21 | Correct | 25 ms | 612 KB | Output is correct |
22 | Correct | 26 ms | 612 KB | Output is correct |
23 | Correct | 6 ms | 612 KB | Output is correct |
24 | Correct | 29 ms | 740 KB | Output is correct |
25 | Correct | 5 ms | 740 KB | Output is correct |
26 | Correct | 12 ms | 740 KB | Output is correct |
27 | Correct | 33 ms | 740 KB | Output is correct |
28 | Correct | 17 ms | 740 KB | Output is correct |
29 | Correct | 7 ms | 740 KB | Output is correct |
30 | Correct | 3 ms | 740 KB | Output is correct |
31 | Correct | 27 ms | 740 KB | Output is correct |
32 | Correct | 236 ms | 740 KB | Output is correct |
33 | Correct | 56 ms | 740 KB | Output is correct |
34 | Correct | 4527 ms | 740 KB | Output is correct |
35 | Correct | 180 ms | 740 KB | Output is correct |
36 | Correct | 375 ms | 740 KB | Output is correct |
37 | Correct | 1781 ms | 740 KB | Output is correct |
38 | Execution timed out | 5090 ms | 740 KB | Time limit exceeded |
39 | Halted | 0 ms | 0 KB | - |