QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287191#7683. Hard Brackets ProblemDetachWA 23ms3544kbC++171.2kb2023-12-19 22:25:552023-12-19 22:25:56

Judging History

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

  • [2023-12-19 22:25:56]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:3544kb
  • [2023-12-19 22:25:55]
  • 提交

answer

#include <bits/stdc++.h>
// #include <algorithm>
// #include <queue>
// #include <map>
// #include <iostream>
// #include <string>
// #include <set>
#define endl '\n'

using namespace std;

using LL = long long;
using PII = pair<int, int>;
using i128 = __int128_t;
using ULL = unsigned long long;

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, N = 1e6 + 5;
const LL LINF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
    string s;
    cin >> s;
    
    int n = s.size(), cnt[2] = {0};
    for(int i = 0; i < n; i ++ )
    {
        int k;
        if(s[i] == '(') cnt[0] ++ ;
        else cnt[1] ++ ;
    }

    if(cnt[0] > cnt[1])
    {
        cout << "impossible" << endl;
    }
    else 
    {
        int now = 0;
        for(int i = 0; i < n; i ++ )
        {
            if(now == cnt[1]) break;
            cout << s[i];
            if(s[i] == '(') now ++ ;
            else if(now) now -- ;
            if(s[i] == ')') cnt[1] -- ;
        }

        cout << endl;
    }
}   

int main()
{
    // freopen("galactic.in", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int T = 1; 
    cin >> T;

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

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3440kb

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 23ms
memory: 3544kb

input:

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

output:

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

result:

wrong answer the result string is incorrect (test case 1)