#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[100100];
vector<int> pos[26];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
for (int i = 0;i < n;i++) {
pos[s[i] - 'a'].push_back(i);
}
for (int i = 0;i < 26;i++) {
int m = pos[i].size();
if (m & 1) {
cout << -1;
return 0;
}
for (int j = 0;j < m / 2;j++) {
a[pos[i][j]] = -1;
}
for (int j = m / 2;j < m;j++) {
a[pos[i][j]] = 1;
}
}
stack<char> st;
for (int i = 0;i < n;i++) {
if (a[i] == -1) {
st.push(s[i]);
}
else {
if (st.empty()) {
cout << -1;
return 0;
}
if (st.top() != s[i]) {
cout << -1;
return 0;
}
st.pop();
}
}
for (int i = 0;i < n;i++) {
cout << "()"[a[i] == 1];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |