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 nx=1e5+5;
int n;
string s;
stack<int> st;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>s;
n=s.size();
for (auto x:s)
{
if (st.empty()||st.top()!=x) st.push(x);
else st.pop();
}
if (!st.empty()) return cout<<-1, 0;
while (!st.empty()) st.pop();
for (int i=0; i<n; i++)
{
if (st.empty()||st.top()!=s[i]) cout<<'(', st.push(s[i]);
else
{
stack<int> tmp=st;
tmp.push(s[i]);
for (int j=i+1; j<n; j++)
{
if (tmp.empty()||tmp.top()!=s[j]) tmp.push(s[j]);
else tmp.pop();
}
if (tmp.empty()) cout<<'(', st.push(s[i]);
else cout<<')', st.pop();
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |