QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545443 | #7683. Hard Brackets Problem | zzz666 | WA | 117ms | 4780kb | C++20 | 649b | 2024-09-03 12:56:39 | 2024-09-03 12:56:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+4;
void slove()
{
string s;
cin>>s;
stack<char>sta;
char ans[N];
int cnt = 0 ;
for(int i = 0 ; i < s.size() ; i++)
{
if(s[i] == '(')
{
sta.push('(');
continue;
}
if(sta.empty() && s[i] == ')')
{
ans[++cnt] = ')';
continue;
}
if(!sta.empty() && s[i] == ')')
{
ans[++cnt] = '(';
sta.pop();
}
}
if(cnt == 0)
{
cout<<"impossible"<<endl;
return;
}
for(int i = 1 ; i <= cnt ; i ++ )
{
cout<<ans[i];
}
cout<<endl;
}
int main()
{
int tcase;
cin>>tcase;
while(tcase--)
{
slove();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4560kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 117ms
memory: 4780kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
()((( (()()) )(((( ()((( (((() )((()) )())())) )))))( ())( ((((( (((() ()(()( (((()) ))))(( ())(( ((((( ())())( ((((( (())( ())(() (((() ()((( ()((( (((() (((( ))))())) ((( (((( )((( ()(()( ))((( (((() )()( )))(()( (()()( ((()() (((() )((( (((() )(((( (((() )(((() ()((() (((() )))))(( ))))((( )()(( ...
result:
wrong answer the result string is incorrect (test case 1)