# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115244 | sebinkim | Match (CEOI16_match) | C++14 | 32 ms | 1400 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 s[101010];
int dp[101010];
int n;
void die()
{
printf("-1\n");
exit(0);
}
int make(int p, int r)
{
int i, ret;
ret = -1;
for(i=p+1; i<r; i=dp[i]+1){
if(s[i] == s[p]) ret = i;
}
if(ret == -1) die();
s[p] = '('; s[ret] = ')';
for(i=p+1; i<ret; ){
if(dp[i] == n) die();
i = make(i, ret) + 1;
if(i > ret) die();
}
return ret;
}
int main()
{
int i, j;
scanf("%s", s);
n = strlen(s);
for(i=n-1; i>=0; i--){
for(j=i+1; s[i] != s[j] && j<n; j=dp[j]+1);
dp[i] = j;
}
for(i=0; i<n; ){
if(dp[i] == n) die();
i = make(i, n) + 1;
if(i > n) die();
}
printf("%s\n", s);
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... |