# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53089 |
2018-06-28T10:17:11 Z |
Diuven |
Match (CEOI16_match) |
C++11 |
|
20 ms |
13500 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;
int n;
char S[MX], R[MX];
int P[MX][30];
void init(){
for(int j=0; j<='z'-'a'; j++)
P[1][j]=0;
for(int i=2; i<=n; i++){
for(int j=0; j<='z'-'a'; j++){
if(S[i]-'a'==j) P[i][j]=i;
else{
int k=P[i-1][S[i]-'a'];
if(k<=1) P[i][j]=0;
else P[i][j]=P[k-1][j];
}
}
}
}
bool solve(int s, int e){
if(e<=s) return e<s;
int m=P[e][S[s]-'a'];
if(m<=s) return false;
R[s]='('; R[m]=')';
return solve(s+1,m-1)&&solve(m+1,e);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>(S+1);
for(int i=1; S[i]!=0; i++) n=i;
init();
if(!solve(1,n)){
cout<<-1;
return 0;
}
cout<<(R+1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
764 KB |
Output is correct |
6 |
Correct |
2 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
764 KB |
Output is correct |
6 |
Correct |
2 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
788 KB |
Output is correct |
8 |
Correct |
3 ms |
1328 KB |
Output is correct |
9 |
Correct |
3 ms |
1456 KB |
Output is correct |
10 |
Correct |
3 ms |
1528 KB |
Output is correct |
11 |
Correct |
3 ms |
1544 KB |
Output is correct |
12 |
Correct |
11 ms |
8328 KB |
Output is correct |
13 |
Correct |
12 ms |
9004 KB |
Output is correct |
14 |
Correct |
13 ms |
9752 KB |
Output is correct |
15 |
Correct |
14 ms |
11288 KB |
Output is correct |
16 |
Correct |
16 ms |
11288 KB |
Output is correct |
17 |
Correct |
20 ms |
11948 KB |
Output is correct |
18 |
Correct |
16 ms |
11948 KB |
Output is correct |
19 |
Correct |
20 ms |
12716 KB |
Output is correct |
20 |
Correct |
11 ms |
12716 KB |
Output is correct |
21 |
Correct |
18 ms |
13500 KB |
Output is correct |