# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
42443 | 2018-02-27T08:18:03 Z | nonocut | 조교 (CEOI16_popeala) | C++14 | 3 ms | 912 KB |
#include<bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; struct node { int cnt[26]; node() { for(int i=0;i<26;i++) cnt[i] = 0; } bool operator < (node a) const { for(int i=0;i<26;i++) { if(a.cnt[i]!=cnt[i]) return a.cnt[i]<cnt[i]; } return 0; } }; int n; char s[maxn], a[maxn], ans[maxn]; node val[maxn]; map<node, set<int>> pos[26]; void solve(int l, int r) { if(l>r) return ; int x = *(--pos[s[l]-'a'][val[l-1]].upper_bound(r)); // printf("solve %d %d => x = %d\n",l,r,x); ans[l] = '('; ans[x] = ')'; solve(l+1,x-1); solve(x+1,r); } int main() { scanf(" %s",s); n = strlen(s); int r = 0; for(int i=0;i<n;i++) { val[i] = val[i-1]; a[++r] = s[i]-'a'; val[i].cnt[s[i]-'a']++; while(r>=2 && a[r]==a[r-1]) { val[i].cnt[a[r]]-=2; r-=2; } pos[s[i]-'a'][val[i]].insert(i); // printf("i = %d (%c) : val = ",i,s[i]); // for(int j=0;j<5;j++) printf("%d",val[i].cnt[j]); // printf("\n"); } if(r>0) return !printf("-1"); solve(0,n-1); printf("%s",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 756 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 912 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |