QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#678910 | #7683. Hard Brackets Problem | Displace_# | WA | 0ms | 3600kb | C++14 | 630b | 2024-10-26 16:24:34 | 2024-10-26 16:24:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+86;
int T;
string s;
int main()
{
cin>>T;
while(T--)
{
string as;
cin>>s;
int sm=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='(') sm++;
if(sm&&s[i]==')') sm--;
}
if(sm)
{
cout<<"impossible"<<endl;
continue;
}
int i=0,j=0;
while(i<s.size())
{
if(s[i]==')')
{
if(as[j]=='(') i++;
else as[++j]=s[i],i++;
}
else if(s[i]=='(')
{
if(s[i+1]=='(') as[++j]=s[i],i++;
else as[++j]=s[i],i+=2;
}
}
for(int i=0;i<=j;i++) cout<<as[i];
cout<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3600kb
input:
3 ((())) ( )))()
output:
result:
wrong answer the answer string contains illegal characters (test case 1)