#include <bits/stdc++.h>
using namespace std;
string s, a;
int n, st[100000], sti;
vector<int> occ[26];
inline void fk() {
cout << -1;
exit(0);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
n=s.size();
for(int i=0; i<n; ++i)
occ[s[i]-'a'].push_back(i);
a.resize(n);
for(int i=0; i<26; ++i) {
if(occ[i].size()&1)
fk();
for(int j=0; j<(int)occ[i].size()-1-j; ++j)
a[occ[i][j]]='(', a[occ[i][occ[i].size()-1-j]]=')';
}
for(int i=0; i<n; ++i) {
if(a[i]==')'&&(!sti||s[st[--sti]]!=s[i]))
fk();
else if(a[i]=='(')
st[sti++]=i;
}
cout << a;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |