QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#255020#7683. Hard Brackets ProblemGCnoodlesbot#WA 15ms3620kbC++20954b2023-11-18 14:32:232023-11-18 14:32:23

Judging History

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

  • [2023-11-18 14:32:23]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3620kb
  • [2023-11-18 14:32:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
    string s;
    cin >> s;
    vector<int> stk;
    string ans = "";
    int n = (int)s.size();
    int f = 0;
    for (int i = 0; i < n; i++) {
        if (!stk.size()) {
            ans += string(f, ')');
            f = 0;
        }
        if (s[i] == '(') {
            if (i && s[i - 1] == ')' && stk.size()) ans += ')';
            f += 1;
            stk.push_back(1);
            ans += '(';
        } else {
            if (stk.size()) {
                stk.pop_back();
            } else {
                ans += ')';
            }
        }
    }
    if (stk.size()) {
        cout << "impossible\n";
    } else {
        cout << ans << "\n";
    }
    return ;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    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: 3620kb

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 3608kb

input:

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

output:

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

result:

wrong answer the output is too long (test case 5)