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;
typedef long long int64;
const int maxn = 2e3 + 2;
string rs;
string s;
int n;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> s;
n = s.size();
rs = string(n, '0');
stack <char> st;
for (int i = 0; i < n; i++){
auto check = [&, st] () mutable -> bool {
st.push(s[i]);
for (int j = i + 1; j < n; j++){
if (!st.empty() && s[j] == st.top()) st.pop();
else st.push(s[j]);
}
return st.empty();
};
if (check()) {
rs[i] = '(';
st.push(s[i]);
}
else {
rs[i] = ')';
if (!st.empty() && st.top() == s[i]) st.pop();
else {
cout << "-1\n";
return 0;
}
}
}
if (st.empty()) cout << rs;
else cout << "-1";
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... |