QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#662034#7683. Hard Brackets ProblemxDarkbluexWA 59ms3584kbC++171.3kb2024-10-20 20:12:412024-10-20 20:13:12

Judging History

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

  • [2024-10-20 20:13:12]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:3584kb
  • [2024-10-20 20:12:41]
  • 提交

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 = "";
    std::stack<char> stk, input;
    for (int i = 0; i < len; i++) {
        while (s[i] == ')') {
            if (stk.size()) {
                ans += ')';
                stk.pop();
                input.emplace(')');
            }
            else {
                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 += '(';
            stk.emplace(')');
            len--;
        }
    }
    while (input.size()) {
        while (stk.size()) {
            ans += ')';
            stk.pop();
        }
        ans += ')';
        input.pop();
    }
    std::cout << ans << '\n';

}

int main() {
    int T;
    std::cin >> T;

    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

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

output:

((()
impossible
)))()

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 59ms
memory: 3584kb

input:

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

output:

impossible
()())()))
)()()()()
impossible
((())()))
impossible
)()))())))
impossible
impossible
()((()()
(()())())
impossible
(())(())))))
impossible
impossible
impossible
()))()))()
impossible
impossible
()))(())))
(()(())))))
())((()
impossible
(()(())))))
impossible
impossible
impossible
impossib...

result:

wrong answer Jury has the answer but participant has not (test case 12)