# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
63161 | 2018-08-01T01:33:26 Z | khsoo01 | 괄호 문자열 (CEOI16_match) | C++11 | 22 ms | 12652 KB |
#include<bits/stdc++.h> using namespace std; const int N = 100005; int n, dt[N][26]; char a[N], b[N]; void solve (int S, int E) { if(S>E) return; int T = dt[E][a[S]]; if(T <= S) { puts("-1"); exit(0); } b[S] = '('; b[T] = ')'; solve(S+1, T-1); solve(T+1, E); } int main() { scanf("%s",a+1); n = strlen(a+1); for(int i=1;i<=n;i++) { a[i] -= 'a'; if(i == 1 || dt[i-1][a[i]] < 2) { for(int j=0;j<26;j++) { dt[i][j] = -1; } } else { int T = dt[i-1][a[i]] - 1; for(int j=0;j<26;j++) { dt[i][j] = dt[T][j]; } } dt[i][a[i]] = i; } solve(1, n); printf("%s",b+1); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 420 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 420 KB | Output is correct |
4 | Correct | 4 ms | 468 KB | Output is correct |
5 | Correct | 3 ms | 596 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 4 ms | 760 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 420 KB | Output is correct |
4 | Correct | 4 ms | 468 KB | Output is correct |
5 | Correct | 3 ms | 596 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 4 ms | 760 KB | Output is correct |
8 | Correct | 4 ms | 1224 KB | Output is correct |
9 | Correct | 5 ms | 1356 KB | Output is correct |
10 | Correct | 6 ms | 1380 KB | Output is correct |
11 | Correct | 4 ms | 1448 KB | Output is correct |
12 | Correct | 14 ms | 7496 KB | Output is correct |
13 | Correct | 15 ms | 8188 KB | Output is correct |
14 | Correct | 15 ms | 8892 KB | Output is correct |
15 | Correct | 19 ms | 10372 KB | Output is correct |
16 | Correct | 19 ms | 10372 KB | Output is correct |
17 | Correct | 19 ms | 11036 KB | Output is correct |
18 | Correct | 19 ms | 11036 KB | Output is correct |
19 | Correct | 19 ms | 11788 KB | Output is correct |
20 | Correct | 15 ms | 11788 KB | Output is correct |
21 | Correct | 22 ms | 12652 KB | Output is correct |