QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661995 | #7683. Hard Brackets Problem | xDarkbluex | WA | 36ms | 3740kb | C++17 | 919b | 2024-10-20 19:51:51 | 2024-10-20 19:51:56 |
Judging History
answer
#include <bits/stdc++.h>
void solve() {
std::string s;
std::cin >> s;
int len = s.size();
if (len == 1) {
if (s[0] == '(') std::cout << "impossible\n";
else std::cout << ")\n";
return;
}
std::string ans = "";
for (int i = 0, j = len - 1; i <= j; i++, j--) {
while (s[i] == ')' && i < j) {
ans += ')';
i++;
}
if (i != j && s[i] == s[j]) {
std::cout << "impossible\n";
return;
}
if (i == j) {
if (s[i] == ')') ans += ')';
else {
std::cout << "impossible\n";
return;
}
break;
}
ans += '(';
}
std::cout << ans << '\n';
}
int main() {
int T;
std::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: 3740kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 36ms
memory: 3596kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())( impossible impossible impossible impossible )()))()) impossible impossible impossible impossible impossible (())(( impossible impossible impossible impossible impossible impossible ()))(( (()(( impossible impossible (()(( impossible impossible impossible impossible impossible impos...
result:
wrong answer the result string is incorrect (test case 2)