QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643387#7683. Hard Brackets ProblemospoasaWA 14ms3860kbC++14952b2024-10-15 20:57:382024-10-15 20:57:39

Judging History

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

  • [2024-10-15 20:57:39]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:3860kb
  • [2024-10-15 20:57:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;

char stk[N];
void solve()
{
    int top = 0;
    string K, ans;
    cin >> K;
    int n = K.size();
    K = ' ' + K;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        if(K[i] == '(') {
            for(int j = 1; j <= cnt; j++) {
                ans += ')';
            }
            ans += '(';
            stk[++top] = '(';
            cnt = 0;
        }

        else {
            if(stk[top] == '(') top--, cnt++;
            else {
                ans += ')';
                stk[++top] = ')';
            }
        }
    }

    for(int i = top; i >= 1; i--) {
        if(stk[i] == '(') {
            cout << "impossible" << '\n';
            return;
        }
    }
    cout << ans << '\n';

}
int main()
{
    ios::sync_with_stdio(0);
    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: 3596kb

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 14ms
memory: 3860kb

input:

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

output:

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 2)