QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733046#7683. Hard Brackets ProblemhoshinomiyakoWA 12ms1608kbC++14985b2024-11-10 16:57:202024-11-10 16:57:20

Judging History

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

  • [2024-11-10 16:57:20]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:1608kb
  • [2024-11-10 16:57:20]
  • 提交

answer

#include <cstdio>
#include <cstring>
using namespace std;
char s[1000010];
int main()
{
    int t=0,nu=0,l=0,p=0,ll=0,a=0,b=0;
    scanf("%d",&t);
    while(t--){
        p=-1;
        ll=-1;
        scanf("%s",s);
        l=strlen(s);
        for(int i=0;i<l;++i){
            if(s[i]=='('){
                nu++;
                ll=i;
                if(i==0||s[i-1]==')')p=i;
            }
            else nu--;
            if(nu<0)nu=0;
        }
        if(nu>0)printf("impossible\n");
        else{
            for(int i=0;i<p;++i)putchar(s[i]);
//            putchar('a');
            a=ll-p+1;
            b=l-ll-1;
            for(int i=0;i<a;++i)putchar('(');
//            putchar('b');
            if(b>a)for(int i=0;i<b;++i)putchar(')');
//            printf("\ndebug p=%d ll=%d a=%d b=%d\n",p,ll,a,b);
            putchar('\n');
        }
    }
    return 0;
}

/*
4
((()))
(
)))()
((()))()
*/
/*
(((
impossible
)))(
*/

詳細信息

Test #1:

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

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 1564kb

input:

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

output:

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

result:

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