QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466758 | #7683. Hard Brackets Problem | yurongyi# | WA | 12ms | 3644kb | C++14 | 640b | 2024-07-08 09:29:50 | 2024-07-08 09:29:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
string s, ans;
int cnt1 = 0, cnt2 = 0;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Cases;
cin >> Cases;
while(Cases--){
cin >> s;
ans.clear();
cnt1 = cnt2 = 0;
for(auto c : s){
if(c == '('){
while(cnt2){
ans.push_back(')');
cnt2--;
}
cnt1++;
}
else{
if(cnt1){
ans.push_back('(');
cnt1--, cnt2++;
}
else
ans.push_back(')');
}
// cout << cnt1 << endl;
}
if(cnt1)
cout << "impossible\n";
else
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 3620kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())()) )()()()( impossible (())(() impossible )()))())) impossible impossible ()()((( ()(())() ())(()))( (())(()) impossible impossible ()(())(( ()))()))( ()(())(( impossible ()))(() ()((() ())((( impossible ()((() impossible impossible impossible impossible impossible ())(()))( impossi...
result:
wrong answer the result string is incorrect (test case 2)