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 nmax=1e5+42;
int n;
string inp;
string outp;
stack<int> active,mem;
bool check(int pos)
{
while(pos<n)
{
if(active.size()==0)active.push(pos);
else if(inp[active.top()]==inp[pos])active.pop();
else active.push(pos);
pos++;
}
return active.size()==0;
}
int main()
{
cin>>inp;
n=inp.size();
if(check(0)==0)
{
printf("-1\n");
return 0;
}
for(int i=0;i<n;i++)
{
mem=active;
active.push(i);
bool possible=check(i+1);
active=mem;
if(possible)
{
outp.push_back('(');
active.push(i);
}
else
{
outp.push_back(')');
active.pop();
}
}
cout<<outp<<endl;
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... |