# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221164 | 2020-04-09T15:44:52 Z | DodgeBallMan | Match (CEOI16_match) | C++14 | 27 ms | 13696 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char s[N], ans[N]; int n, last[N][30]; void solve( int l, int r ) { if( l > r ) return ; if( l % 2 == r % 2 ) { printf("-1"); exit( 0 ); } int idx = last[r][s[l]-'a']; ans[l] = '(', ans[idx] = ')'; solve( l + 1, idx-1 ), solve( idx+1, r ); } int main() { scanf("%s",&s[1]); n = strlen( &s[1] ); for( int i = 0 ; i < 26 ; i++ ) last[0][i] = 1; for( int i = 1 ; i <= n ; i++ ) { int now = s[i] - 'a'; for( int j = 0 ; j < 26 ; j++ ) { if( j == now ) last[i][j] = i; else last[i][j] = last[last[i-1][now]-1][j]; } } solve( 1, n ); for( int i = 1 ; i <= n ; i++ ) printf("%c",ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 640 KB | Output is correct |
8 | Correct | 6 ms | 1152 KB | Output is correct |
9 | Correct | 6 ms | 1280 KB | Output is correct |
10 | Correct | 6 ms | 1280 KB | Output is correct |
11 | Correct | 7 ms | 1408 KB | Output is correct |
12 | Correct | 15 ms | 8320 KB | Output is correct |
13 | Correct | 16 ms | 9088 KB | Output is correct |
14 | Correct | 17 ms | 9856 KB | Output is correct |
15 | Correct | 27 ms | 11520 KB | Output is correct |
16 | Correct | 18 ms | 11520 KB | Output is correct |
17 | Correct | 19 ms | 12160 KB | Output is correct |
18 | Correct | 19 ms | 11904 KB | Output is correct |
19 | Correct | 22 ms | 12800 KB | Output is correct |
20 | Correct | 15 ms | 8576 KB | Output is correct |
21 | Correct | 22 ms | 13696 KB | Output is correct |