QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771249 | #7683. Hard Brackets Problem | xsdgp | WA | 10ms | 3728kb | C++20 | 725b | 2024-11-22 11:07:20 | 2024-11-22 11:07:21 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
string s;
bool vis[1000005];
void solve()
{
cin>>s;
int cnt=0;
for(int i=0;i<s.size();i++)
vis[i]=0;
for(int i=0;i<s.size();i++)
if(s[i]=='(')cnt++;
if(cnt<=s.size()-cnt)
{
cnt=0;
for(int i=0;i<s.size();i++)
if(s[i]=='(')cnt++;
else if(cnt)
{
vis[i]=1;
cnt--;
}
for(int i=s.size()-1;i>=0;i--)
if(s[i]==')'&&vis[i])s.pop_back();
else break;
cout<<s<<endl;
}
else cout<<"impossible"<<endl;
}
signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
/*
3
((()))
(
)))()
(()(())))
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 3728kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
())(()()( ()())())) )()()()( ())()(())( ((())())) )(())()))( )()))()))) )))))(((( impossible ()((()( (()())()) ())(()))( (())(()))) ))))(()(( ()))(())(( ()((())( ()))()))( ()((())( ()()))((( ()))(())) (()(()))) ())((( ())()((( (()(()))) impossible ))))())))( impossible impossible impossible ())(()))...
result:
wrong answer the result string is incorrect (test case 1)