QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656727 | #7683. Hard Brackets Problem | test_algth | WA | 20ms | 3772kb | C++14 | 884b | 2024-10-19 13:37:12 | 2024-10-19 13:37:15 |
Judging History
answer
#include <bits/stdc++.h>
const int MAXN = 1.01E6;
char A[MAXN];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int testCase = 1;
std::cin >> testCase;
while (testCase--) {
std::cin >> A;
bool ok = true;
std::vector <char> Ans;
int now = 0, N = strlen(A), e = 0;
for (int i = 0; i < N; ++i) {
char a = A[i];
if (a == '(') {
if (e && now > 0) Ans.push_back(')');
Ans.push_back('('), ++now, e = 0;
}
else {
if (!now) Ans.push_back(')');
now = std::max(0, now - 1);
e = 1;
}
// printf("(%d, %d)\n", i, now);
}
if (now == 0) {
for (char a : Ans)
std::cout << a;
std::cout << '\n';
} else {
std::cout << "impossible" << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 20ms
memory: 3544kb
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)