QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#467077#7683. Hard Brackets Problemadanmaip#WA 12ms1576kbC++14826b2024-07-08 13:39:402024-07-08 13:39:42

Judging History

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

  • [2024-07-08 13:39:42]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:1576kb
  • [2024-07-08 13:39:40]
  • 提交

answer

#include <cstdio>
#include <cstdlib>
#include <list>
char a[1000000];
char ans[1000000];
int n;
int getl(char* p){
	int i=0;
	char c=0;
	while (c!='('&&c!=')') c=getchar();
	while (c=='('||c==')') {
		p[i++]=c;
		c=getchar();
	}
	return i;
}
int main(){
	int T;
	scanf("%d", &T);
	while(T--){
		for (int i=0; a[i]!=0; ++i) a[i]=0;
		for (int i=0; ans[i]!=0; ++i) ans[i]=0;
		n=getl(a);
		int ansi=0;
		int cntlft=0;
		int cntrgt=0;
		for (int i=0; i<n; ++i){
			if (a[i]=='('){
				cntrgt=0;
				++cntlft;
				ans[ansi++]='(';
			}
			else if (a[i]==')'){
				++cntrgt;
				--cntlft;
				ans[ansi++]=')';
			}
		}
		if (cntlft>0) {
			printf("impossible\n");
			continue;
		}
		--ansi;
		if (cntrgt>0) while (ans[ansi]==')') ans[ansi--]=0;
	 	printf("%s\n", ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

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

input:

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

output:

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

result:

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