QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662005#7683. Hard Brackets ProblemxDarkbluexWA 43ms3592kbC++17879b2024-10-20 19:59:132024-10-20 19:59:45

Judging History

你现在查看的是最新测评结果

  • [2024-10-20 19:59:45]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:3592kb
  • [2024-10-20 19:59:13]
  • 提交

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; i < len; i++) {
        while (s[i] == ')') {
            ans += ')';
            i++;
        }
        if (i == len - 1 && s[i] == '(') {
            std::cout << "impossible\n";
            return;
        }
        if (i + 1 < len && s[i] == '(' && s[i + 1] == ')') {
            i++;
            ans += "()";
        } else if (s[i] == '(' && s[len - 1] == ')') {
            ans += '(';
            len--;
        }
    }
    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: 3592kb

input:

3
((()))
(
)))()

output:

((()
impossible
)))()

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 43ms
memory: 3556kb

input:

100000
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
(()())())
())(()))()
(())(())))
))))(()(()
()))(())((
()((())())
()))()))()
()((())())
()()))((()
()))(()))
(()(())))
())((()))
())()((())
(()(())))
()(((()())
))))())))(
((((()()()
(()(...

output:

impossible
()())()))
)()()()()
impossible
((())()
impossible
)()))())))
impossible
impossible
()((()()
(()())()
impossible
(())(())))
impossible
impossible
impossible
()))()))()
impossible
impossible
()))(()))
(()(())))
())((()
impossible
(()(())))
impossible
impossible
impossible
impossible
impossi...

result:

wrong answer the result string is incorrect (test case 5)