QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738214#7683. Hard Brackets Problemqikala7777WA 11ms3568kbC++231.1kb2024-11-12 18:16:332024-11-12 18:16:33

Judging History

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

  • [2024-11-12 18:16:33]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3568kb
  • [2024-11-12 18:16:33]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=1e6+7,inf=0x3f3f3f3f;const LL Linf=0x3f3f3f3f3f3f3f3fLL;
LL qsm(LL a,LL b,LL p){LL res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
LL lowbit(LL x){return x&-x;}
string s;
void solve(){
    cin>>s;
    int n=s.size();
    s="$"+s;
    int rr=0;
    string ans;
    bool f=1;
    for(int i=1;i<=n;i++){
        if(s[i]=='('){
            if(!f){
                cout<<"impossible"<<endl;
                return;
            }
            ans+='(';
            rr++;
        }else{
            if(rr){
                rr--;
                f=0;
            }else{
                ans+=')';
                f=1;
            }
        }
    }
    if(rr){
        cout<<"impossible"<<endl;
    }else{
        cout<<ans<<endl;
    }
}
int main(){
   IOS
   int T=1;
   cin>>T;
    while(T--)solve();

    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3568kb

input:

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

output:

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

result:

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