# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
97290 | 2019-02-14T19:31:10 Z | dalgerok | 괄호 문자열 (CEOI16_match) | C++14 | 24 ms | 11960 KB |
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; string s; int n, a[N][26]; char ans[N]; void rec(int l, int r){ if(l >= r){ return; } int pos = a[r][s[l]]; if(pos <= l){ cout << "-1"; exit(0); } ans[l] = '('; ans[pos] = ')'; rec(l + 1, pos - 1); rec(pos + 1, r); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> s; for(auto &it : s){ it -= 'a'; } n = (int)s.size(); memset(a, -1, sizeof(a)); for(int i = 0; i < n; i++){ for(int j = 0; j < 26; j++){ if(s[i] == j){ a[i][j] = i; } else if(i - 1 >= 0 && a[i - 1][s[i]] - 1 >= 0){ a[i][j] = a[a[i - 1][s[i]] - 1][j]; } } } rec(0, n - 1); for(int i = 0; i < n; i++){ cout << ans[i]; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 10496 KB | Output is correct |
2 | Correct | 9 ms | 10496 KB | Output is correct |
3 | Correct | 10 ms | 10496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 10496 KB | Output is correct |
2 | Correct | 9 ms | 10496 KB | Output is correct |
3 | Correct | 10 ms | 10496 KB | Output is correct |
4 | Correct | 9 ms | 10496 KB | Output is correct |
5 | Correct | 10 ms | 10496 KB | Output is correct |
6 | Correct | 12 ms | 10496 KB | Output is correct |
7 | Correct | 10 ms | 10496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 10496 KB | Output is correct |
2 | Correct | 9 ms | 10496 KB | Output is correct |
3 | Correct | 10 ms | 10496 KB | Output is correct |
4 | Correct | 9 ms | 10496 KB | Output is correct |
5 | Correct | 10 ms | 10496 KB | Output is correct |
6 | Correct | 12 ms | 10496 KB | Output is correct |
7 | Correct | 10 ms | 10496 KB | Output is correct |
8 | Correct | 11 ms | 10624 KB | Output is correct |
9 | Correct | 9 ms | 10624 KB | Output is correct |
10 | Correct | 10 ms | 10624 KB | Output is correct |
11 | Correct | 10 ms | 10672 KB | Output is correct |
12 | Correct | 17 ms | 11392 KB | Output is correct |
13 | Correct | 16 ms | 11392 KB | Output is correct |
14 | Correct | 24 ms | 11620 KB | Output is correct |
15 | Correct | 18 ms | 11904 KB | Output is correct |
16 | Correct | 19 ms | 11904 KB | Output is correct |
17 | Correct | 23 ms | 11960 KB | Output is correct |
18 | Correct | 20 ms | 11392 KB | Output is correct |
19 | Correct | 21 ms | 11648 KB | Output is correct |
20 | Correct | 15 ms | 11520 KB | Output is correct |
21 | Correct | 19 ms | 11768 KB | Output is correct |