# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61215 | junodeveloper | Match (CEOI16_match) | C++17 | 25 ms | 12852 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[100010],a[100010];
int pre[100010][26];
void solve(int l, int r) {
if(l > r) return;
if(pre[r][s[l]-'a'] <= l) { puts("-1"); exit(0); }
a[l] = '(', a[pre[r][s[l]-'a']] = ')';
solve(l+1, pre[r][s[l]-'a']-1), solve(pre[r][s[l]-'a']+1, r);
}
int main() {
scanf("%s", s);
int n = strlen(s);
for(int i=0; i<n; i++) {
for(int j=0; j<26; j++)
if(j == s[i]-'a') pre[i][j] = i;
else if(i && pre[i-1][s[i]-'a'] > 0) pre[i][j] = pre[pre[i-1][s[i]-'a']-1][j];
else pre[i][j] = -1;
}
solve(0,n-1);
puts(a);
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... |