# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52901 | 2018-06-27T06:56:55 Z | 윤교준(#1384) | Match (CEOI16_match) | C++11 | 2 ms | 356 KB |
#include <bits/stdc++.h> #define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15); #define pb push_back #define eb emplace_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define sorv(V) sort(allv(V)) #define upmin(a,b) (a)=min((a),(b)) #define INF (0x3f3f3f3f) #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = 2005; bitset<MAXN> B[MAXN]; char A[MAXN], Ans[MAXN]; int N; void f(int s, int e) { if(s+1 == e) { Ans[s] = '('; Ans[e] = ')'; return; } if(B[s+1][e-1]) { Ans[s] = '('; Ans[e] = ')'; f(s+1, e-1); return; } for(int i = e-2; s < i; i -= 2) { if(A[s] != A[i] || !B[i+1][e]) continue; if(s+1 < i && !B[s+1][i-1]) continue; Ans[s] = '('; Ans[i] = ')'; if(s+1 < i) f(s+1, i-1); f(i+1, e); } } int main() { scanf(" %s", A+1); N = int(strlen(A+1)); if(N&1) { puts("-1"); return 0; } for(int i = 1; i < N; i++) B[i][i+1] = (A[i] == A[i+1]); for(int d = 3; d < N; d += 2) { for(int i = 1; i+d <= N; i++) { if(A[i] == A[i+d] && B[i+1][i+d-1]) { B[i][i+d] = true; continue; } for(int k = i+1; k < i+d; k += 2) { if(B[i][k] && B[k+1][i+d]) { B[i][i+d] = true; break; } } } } if(!B[1][N]) { puts("-1"); return 0; } f(1, N); for(int i = 1; i <= N; i++) putchar(Ans[i]); puts(""); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Incorrect | 2 ms | 356 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Incorrect | 2 ms | 356 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Incorrect | 2 ms | 356 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |