# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59580 | 2018-07-22T12:27:51 Z | octopuses | 괄호 문자열 (CEOI16_match) | C++17 | 2000 ms | 1324 KB |
//Giorgi Kldiashvili #include <bits/stdc++.h> #define ll long long #define fr first #define sc second #define M 1000000007ll using namespace std; const int N = 100020; int n; char ch[N]; string a; inline bool go(int v, stack < int > q) { q.push(v); for(int i = v + 1; i <= n; ++ i) { if(!q.size() || a[q.top()] != a[i]) q.push(i); else q.pop(); } if(q.size()) return false; return true; } stack < int > q; int main() { scanf("%s", &ch); a = "$" + string(ch) + "$"; n = strlen(ch); for(int i = 1; i <= n; ++ i) { if(!q.size() || a[q.top()] != a[i]) q.push(i); else q.pop(); } if(q.size()) return printf("-1"), 0; while(q.size()) q.pop(); q.push(1); printf("("); for(int i = 2; i <= n; ++ i) { if(!q.size() || a[q.top()] != a[i]) q.push(i), printf("("); else { if(go(i, q)) q.push(i), printf("("); else q.pop(), printf(")"); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 3 ms | 488 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 3 ms | 488 KB | Output is correct |
4 | Correct | 5 ms | 488 KB | Output is correct |
5 | Correct | 5 ms | 572 KB | Output is correct |
6 | Correct | 6 ms | 628 KB | Output is correct |
7 | Correct | 12 ms | 628 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 3 ms | 488 KB | Output is correct |
4 | Correct | 5 ms | 488 KB | Output is correct |
5 | Correct | 5 ms | 572 KB | Output is correct |
6 | Correct | 6 ms | 628 KB | Output is correct |
7 | Correct | 12 ms | 628 KB | Output is correct |
8 | Correct | 101 ms | 644 KB | Output is correct |
9 | Correct | 101 ms | 644 KB | Output is correct |
10 | Correct | 84 ms | 712 KB | Output is correct |
11 | Correct | 69 ms | 760 KB | Output is correct |
12 | Execution timed out | 2054 ms | 1324 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |