QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#614040 | #7683. Hard Brackets Problem | Pepinot | WA | 47ms | 3632kb | C++20 | 970b | 2024-10-05 15:25:51 | 2024-10-05 15:25:52 |
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(')');
}
}
}
bool is=false;
while(sk.size()) {
if(sk.top()=='(') {
is=true;
break;
}
sk.pop();
}
// while(sk.size()) {
// cout<<sk.top();
// sk.pop();
// }
if(is) cout<<"impossible";
else 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
((()))
(
)))()
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 47ms
memory: 3632kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible (()()) )(((( impossible (((() impossible )())())) impossible impossible ((((( (((() ()(()( (((()) impossible impossible ((((( ())())( ((((( impossible ())(() (((() ()((( impossible (((() impossible impossible impossible impossible impossible ()(()( impossible impossible impossible )))(()(...
result:
wrong answer the result string is incorrect (test case 2)