This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[j]) {
stk_cp.push_back(s[j]);
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |