# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
225352 |
2020-04-20T11:11:17 Z |
brcode |
Match (CEOI16_match) |
C++14 |
|
39 ms |
13432 KB |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+5;
string s;
int dp[MAXN][30];
char ans[MAXN];
void solve(int l,int r){
if(l>r){
return;
}
int mid = dp[r][s[l]-'a'];
if(l>=mid){
cout<<-1<<endl;
exit(0);
}
ans[l] = '(';
ans[mid] = ')';
solve(l+1,mid-1);
solve(mid+1,r);
}
int main() {
cin>>s;
int n = s.length();
for(int i=0;i<n;i++){
for(int j=0;j<26;j++){
if(s[i]==j+'a'){
dp[i][j] = i;
}else if(i && dp[i-1][s[i]-'a']>0){
dp[i][j] = dp[dp[i-1][s[i]-'a']-1][j];
}
}
}
solve(0,n-1);
for(int i=0;i<n;i++){
cout<<ans[i];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
1152 KB |
Output is correct |
9 |
Correct |
6 ms |
1280 KB |
Output is correct |
10 |
Correct |
7 ms |
1280 KB |
Output is correct |
11 |
Correct |
6 ms |
1280 KB |
Output is correct |
12 |
Correct |
17 ms |
8192 KB |
Output is correct |
13 |
Correct |
18 ms |
8960 KB |
Output is correct |
14 |
Correct |
22 ms |
9600 KB |
Output is correct |
15 |
Correct |
26 ms |
11136 KB |
Output is correct |
16 |
Correct |
21 ms |
11136 KB |
Output is correct |
17 |
Correct |
26 ms |
11768 KB |
Output is correct |
18 |
Correct |
24 ms |
11776 KB |
Output is correct |
19 |
Correct |
32 ms |
12544 KB |
Output is correct |
20 |
Correct |
18 ms |
8320 KB |
Output is correct |
21 |
Correct |
39 ms |
13432 KB |
Output is correct |