QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395388 | #7683. Hard Brackets Problem | zzuqy# | WA | 10ms | 3856kb | C++14 | 564b | 2024-04-21 14:02:24 | 2024-04-21 14:02:25 |
Judging History
answer
#include <bits/stdc++.h>
char s[1000006], ans[1000006];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%s", s);
int n = std::strlen(s), l = 0;
for (int i = 0; i < n; i++) {
if (s[i] == ')') {
ans[++l] = ')';
continue;
}
int o = 0;
while (i < n && s[i] == '(')
o++, i++, ans[++l] = '(';
while (i < n && o > 0 && s[i] == ')')
o--, i++, ans[++l] = ')';
if (o > 0)
goto FAIL;
}
ans[++l] = 0;
printf("%s\n", ans + 1);
continue;
FAIL:
puts("impossible");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
input:
3 ((())) ( )))()
output:
((())) impossible )))()
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 3852kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()))()) )())()) 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)