# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129981 | TadijaSebez | Match (CEOI16_match) | C++11 | 20 ms | 11640 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 N=100050;
char s[N],ans[N];
int pre[N][26];
bool ok=1;
void Solve(int l, int r)
{
if(l>r) return;
int m=pre[r][s[l]-'a'];
if(m<=l){ ok=0;return;}
ans[l]='(';
ans[m]=')';
Solve(l+1,m-1);
Solve(m+1,r);
}
int main()
{
int n;
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++) for(int j=0;j<26;j++)
{
if(j==s[i]-'a') pre[i][j]=i;
else if(pre[i-1][s[i]-'a']>0) pre[i][j]=pre[pre[i-1][s[i]-'a']-1][j];
else pre[i][j]=0;
}
Solve(1,n);
if(ok) printf("%s",ans+1);
else printf("-1\n");
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... |