이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |