# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
52865 |
2018-06-27T05:31:45 Z |
노영훈(#1382) |
Match (CEOI16_match) |
C++11 |
|
2 ms |
376 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;
int cnt[MX][30];
char S[MX], R[MX];
vector<int> pos[30];
void NOPE(){
cout<<-1;
exit(0);
}
bool valid(int x, int y){
for(int i=0; i<='z'-'a'; i++)
if((cnt[y][i]-cnt[x-1][i])%2!=0) return false;
return true;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>(S+1);
for(int i=1; S[i]!=0; i++) n=i;
for(int i=1; i<=n; i++){
int x=S[i]-'a';
pos[x].push_back(i);
for(int j=0; j<='z'-'a'; j++)
cnt[i][j]=cnt[i-1][j];
cnt[i][x]++;
}
for(int i=0; i<='z'-'a'; i++){
int sz=pos[i].size();
for(int j=0; j<sz; j++){
int x=pos[i][j];
if(R[x]!=0) continue;
for(int k=sz-1; k>=0; k--){
int y=pos[i][k];
if(R[y]!=0) continue;
if(y<=x) break;
if(valid(x,y)){
R[x]='('; R[y]=')';
break;
}
}
}
}
for(int i=1; i<=n; i++) if(R[i]==0) NOPE();
cout<<(R+1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |