QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#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;
}
詳細信息
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)