# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154374 | 2019-09-21T12:09:08 Z | arnold518 | Match (CEOI16_match) | C++14 | 3 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N; char S[MAXN+10], ans[MAXN+10]; int P[MAXN+10][30]; void solve(int l, int r) { if(r<=l) return; int t=P[r][S[l]-'a']; ans[l]='('; ans[t]=')'; solve(l+1, t-1); solve(t+1, r); } int main() { int i, j; scanf("%s", S+1); N=strlen(S+1); vector<char> V; for(i=1; i<=N; i++) { if(!V.empty() && S[i]==V.back()) V.pop_back(); else V.push_back(S[i]); } if(!V.empty()) return !printf("-1"); for(i=1; i<=N; i++) { for(j=0; j<26; j++) { if('a'+j==S[i]) P[i][j]=i; else P[i][j]=P[P[i-1][S[i]-'a']-1][j]; } } solve(1, N); printf("%s", ans+1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Runtime error | 3 ms | 376 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Runtime error | 3 ms | 376 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |