QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#255020 | #7683. Hard Brackets Problem | GCnoodlesbot# | WA | 15ms | 3620kb | C++20 | 954b | 2023-11-18 14:32:23 | 2023-11-18 14:32:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
string s;
cin >> s;
vector<int> stk;
string ans = "";
int n = (int)s.size();
int f = 0;
for (int i = 0; i < n; i++) {
if (!stk.size()) {
ans += string(f, ')');
f = 0;
}
if (s[i] == '(') {
if (i && s[i - 1] == ')' && stk.size()) ans += ')';
f += 1;
stk.push_back(1);
ans += '(';
} else {
if (stk.size()) {
stk.pop_back();
} else {
ans += ')';
}
}
}
if (stk.size()) {
cout << "impossible\n";
} else {
cout << ans << "\n";
}
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
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: 15ms
memory: 3608kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())())) )()()()( impossible ((()())))) impossible )()))()))) impossible impossible ()((()( (()()))()) ())(()))( (())(()))) impossible impossible ()((()( ()))()))( ()((()( impossible ()))(())) (()(())))) ())((( impossible (()(())))) impossible impossible impossible impossible impossible ...
result:
wrong answer the output is too long (test case 5)