QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408981#7683. Hard Brackets Problemlight_ink_dots#WA 28ms3628kbC++14944b2024-05-11 14:19:462024-05-11 14:19:47

Judging History

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

  • [2024-05-11 14:19:47]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:3628kb
  • [2024-05-11 14:19:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int main() {
    static const int maxn = 1000010;
    int t;
    scanf("%d", &t);
    while (t--) {
        static char s[maxn];
        scanf("%s", s + 1);
        int n = strlen(s + 1), i = 1;
        bool ans = true;
        string str;
        while (i <= n) {
            if (s[i] == ')') {
                i++, str += ')';
                continue;
            }
            int c = 1;
            while (i + c <= n && s[i + c] == '(') c++;
            if (i + (c << 1) - 1 > n) {
                ans = false;
                break;
            }
            for (int x = c; x < c << 1; x++) ans &= s[i + x] == ')';
            for (int x = 0; x < c; x++) str += '(';
            for (int x = 0; x < c; x++) str += ')';
            i += c << 1;
        }
        if (!ans)
            str = "impossible";
        cout << str << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

((()))
impossible
)))()

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 28ms
memory: 3628kb

input:

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

output:

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

result:

wrong answer Jury has the answer but participant has not (test case 5)