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 pb push_back
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define forn(i, l, n) for (int i = l; i < int(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
int main() // Ale C.
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("output.txt", "w", stdout);
string str;
cin >> str;
stack<char> st;
string ans = "(";
st.push(str[0]);
int test = 1;
forn(i, 1, str.length())
{
if (test < 0)
break;
if (st.empty())
{
ans += "(";
st.push(str[i]);
test++;
continue;
}
if (st.top() != str[i])
{
ans += "(";
st.push(str[i]);
test++;
}
else
{
ans += ")";
st.pop();
test--;
}
}
cout << (test == 0 ? ans : "-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... |