# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42438 | nonocut | Match (CEOI16_match) | C++14 | 6 ms | 6112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int n;
char s[maxn], a[maxn], ans[maxn];
set<int> pos[30][maxn];
void solve(int l, int r, int cur) {
if(l>r) return ;
int x = *(--pos[s[l]-'a'][cur].upper_bound(r));
ans[l] = '('; ans[x] = ')';
solve(l+1,x-1,cur+1); solve(x+1,r,cur);
}
int main() {
scanf(" %s",s);
n = strlen(s);
int r = 0;
for(int i=0;i<n;i++) {
a[++r] = s[i];
while(r>=2 && a[r]==a[r-1]) r-=2;
pos[s[i]-'a'][r].insert(i);
}
if(r>0) return !printf("-1");
solve(0,n-1,0);
printf("%s",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |