# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
466151 |
2021-08-18T07:11:54 Z |
fuad27 |
Match (CEOI16_match) |
C++17 |
|
1 ms |
332 KB |
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200000
string s;
int n, op[MAXN][26];
char ans[MAXN];
void solve(int l, int r) {
if(l > r) return;
if(op[r][s[l]-'a'] <= l) { cout<<-1<<endl; exit(0); }
ans[l] = '(', ans[op[r][s[l]-'a']] = ')';
solve(l+1, op[r][s[l]-'a']-1), solve(op[r][s[l]-'a']+1, r);
}
int main () {
cin >> s;
n=s.size();
vector<char> st;
for(int i = 0;i<n;i++) {
for(int j = 0;j<26;j++) {
if(j == s[i]-'a')op[i][j] = i;
else if(i > 0 && op[i][s[i]-'a'] > 0)op[i][j] = op[op[i-1][s[i]-'a']-1][j];
else op[i][j] = -1;
}
}
solve(0, n-1);
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |