QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643385#7683. Hard Brackets ProblemospoasaWA 1ms3856kbC++14952b2024-10-15 20:56:362024-10-15 20:56:37

Judging History

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

  • [2024-10-15 20:56:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3856kb
  • [2024-10-15 20:56:36]
  • 提交

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: 1ms
memory: 3856kb

input:

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

output:

(((
impossable
)))(

result:

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