#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
string s;
int ans[22], a[22];
bool ch = 0;
void solve(int bit) {
stack<char> st;
for (int i = 0;i < n;i++) {
a[i] = (bit >> i) & 1;
if (a[i]) {
if (st.empty()) return;
if (st.top() != s[i]) return;
st.pop();
}
else {
st.push(s[i]);
}
}
if (!st.empty()) return;
for (int i = 0;i < n;i++) {
if (ans[i] != a[i]) {
if (ans[i] > a[i]) {
for (int i = 0;i < n;i++) ans[i] = a[i];
}
break;
}
}
ch = 1;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
memset(ans, 0x3f, sizeof ans);
cin >> s;
n = s.size();
for (int v = 0;v < (1 << n);v++) {
solve(v);
}
if (!ch) cout << -1;
else {
for (int i = 0;i < n;i++) {
cout << "()"[ans[i]];
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |