QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#613997 | #7683. Hard Brackets Problem | Pepinot | WA | 23ms | 3772kb | C++20 | 822b | 2024-10-05 15:18:05 | 2024-10-05 15:20:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solveTS() {
string s; cin >> s;
string ss;
vector<char> ans;
stack<char> sk;
for(auto i:s) {
if(i=='(') sk.push(i);
else{
if(sk.size()&&sk.top()=='(') {
sk.pop();
ans.push_back('(');
}
else {
sk.push(i);
ans.push_back(')');
}
}
}
// while(sk.size()) {
// cout<<sk.top();
// sk.pop();
// }
if(ans.empty()) cout<<"impossible";
for(auto i:ans) cout<<i;
cout<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--){
solveTS();
}
}
/*
3
((()))
(
)))()
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3772kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 3592kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
()((( (()()) )(((( ()((( (((() )((()) )())())) )))))( ())( ((((( (((() ()(()( (((()) ))))(( ())(( ((((( ())())( ((((( (())( ())(() (((() ()((( ()((( (((() (((( ))))())) ((( (((( )((( ()(()( ))((( (((() )()( )))(()( (()()( ((()() (((() )((( (((() )(((( (((() )(((() ()((() (((() )))))(( ))))((( )()(( ...
result:
wrong answer the result string is incorrect (test case 1)