# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127212 | Plurm | Match (CEOI16_match) | C++11 | 2 ms | 504 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;
char str[100005];
char ans[100005];
int prefh[100005];
bool recur(int l, int r){
if(r < l) return true;
if((r - l) % 2 == 0) return false;
int mx = -1;
for(int i = l+1; i <= r; i++){
if((prefh[i] ^ prefh[l-1]) == 0 && str[i] == str[l]){
mx = i;
}
}
if(mx == -1) return false;
ans[l] = '(';
ans[mx] = ')';
return recur(l+1, mx-1) && recur(mx+1, r);
}
int main(){
scanf("%s",str+1);
int n = strlen(str+1);
for(int i = 1; i <= n; i++){
prefh[i] = prefh[i-1] ^ (1 << (str[i] - 'a'));
}
if(recur(1, n)){
ans[n+1] = '\0';
printf("%s",ans+1);
}else{
printf("-1");
}
return 0;
}
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... |