QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643369#7683. Hard Brackets ProblemospoasaWA 0ms3652kbC++14957b2024-10-15 20:53:512024-10-15 20:53:51

Judging History

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

  • [2024-10-15 20:53:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-10-15 20:53:51]
  • 提交

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 << "impossable" << '\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: 0
Wrong Answer
time: 0ms
memory: 3652kb

input:

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

output:

(((
impossable
)))(

result:

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