#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
vector<char> stk;
string ans;
for (int i = 0; i < n; i++) {
if (stk.empty() || stk.back() != s[i]) {
stk.push_back(s[i]);
ans.push_back('(');
}
else {
vector<char> stk_cp = stk;
stk_cp.push_back(s[i]);
for (int j = i + 1; j < n; j++) {
if (stk_cp.empty() || stk_cp.back() != s[i]) {
stk_cp.push_back(s[i]);
}
else {
stk_cp.pop_back();
}
}
if (stk_cp.empty()) {
stk.push_back(s[i]);
ans.push_back('(');
}
else {
stk.pop_back();
ans.push_back(')');
}
}
}
if (stk.empty()) {
cout << ans << "\n";
}
else {
cout << "-1\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |