QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408981 | #7683. Hard Brackets Problem | light_ink_dots# | WA | 28ms | 3628kb | C++14 | 944b | 2024-05-11 14:19:46 | 2024-05-11 14:19:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
static const int maxn = 1000010;
int t;
scanf("%d", &t);
while (t--) {
static char s[maxn];
scanf("%s", s + 1);
int n = strlen(s + 1), i = 1;
bool ans = true;
string str;
while (i <= n) {
if (s[i] == ')') {
i++, str += ')';
continue;
}
int c = 1;
while (i + c <= n && s[i + c] == '(') c++;
if (i + (c << 1) - 1 > n) {
ans = false;
break;
}
for (int x = c; x < c << 1; x++) ans &= s[i + x] == ')';
for (int x = 0; x < c; x++) str += '(';
for (int x = 0; x < c; x++) str += ')';
i += c << 1;
}
if (!ans)
str = "impossible";
cout << str << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
input:
3 ((())) ( )))()
output:
((())) impossible )))()
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 3628kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())())) )()()()() impossible impossible impossible )()))()))) impossible impossible impossible impossible ())(()))() (())(()))) impossible impossible impossible ()))()))() impossible impossible ()))(())) impossible ())((())) impossible impossible impossible impossible impossible impossi...
result:
wrong answer Jury has the answer but participant has not (test case 5)