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;
const int N = 1e5 + 10;
int a[N], n;
string s;
bool isval()
{
vector <char> vec;
for (int i = 0; i < n; i++) {
if (a[i] == -1) {
if (vec.empty() || vec.back() != s[i]) return 0;
vec.pop_back();
}
if (a[i] == 1) vec.push_back(s[i]);
if (a[i] == 0) {
if (vec.size() && vec.back() == s[i]) vec.pop_back();
else vec.push_back(s[i]);
}
}
return vec.empty();
}
int main()
{
cin >> s;
n = s.size();
if (!isval()) return cout << -1 << "\n", 0;
for (int i = 0; i < n; i++) {
a[i] = 1;
if (!isval()) a[i] = -1;
}
for (int i = 0; i < n; i++) cout << (a[i] == 1 ? '(' : ')');
cout << "\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... |