QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#614040#7683. Hard Brackets ProblemPepinotWA 47ms3632kbC++20970b2024-10-05 15:25:512024-10-05 15:25:52

Judging History

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

  • [2024-10-05 15:25:52]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:3632kb
  • [2024-10-05 15:25:51]
  • 提交

answer

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

void solveTS() {
    string s; cin >> s;
    string ss;
    vector<char> ans;
    stack<char> sk;
    for(auto i:s) {
        if(i=='(') sk.push(i);
        else{
            if(sk.size()&&sk.top()=='(') {
                sk.pop();
                ans.push_back('(');
            }
            else {
                sk.push(i);
                ans.push_back(')');
            }
        }
    }
    bool is=false;
    while(sk.size()) {
        if(sk.top()=='(') {
            is=true;
            break;
        }
        sk.pop();
    }
    // while(sk.size()) {
    //     cout<<sk.top();
    //     sk.pop();
    // }
    if(is) cout<<"impossible";
    else for(auto i:ans) cout<<i;
    cout<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        solveTS();
    }
}
    /*
3
((()))
(
)))()

     */

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 47ms
memory: 3632kb

input:

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

output:

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

result:

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