QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395388#7683. Hard Brackets Problemzzuqy#WA 10ms3856kbC++14564b2024-04-21 14:02:242024-04-21 14:02:25

Judging History

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

  • [2024-04-21 14:02:25]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3856kb
  • [2024-04-21 14:02:24]
  • 提交

answer

#include <bits/stdc++.h>
char s[1000006], ans[1000006];

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%s", s);
		int n = std::strlen(s), l = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == ')') {
				ans[++l] = ')';
				continue;
			}
			int o = 0;
			while (i < n && s[i] == '(')
				o++, i++, ans[++l] = '(';
			while (i < n && o > 0 && s[i] == ')')
				o--, i++, ans[++l] = ')';
			if (o > 0)
				goto FAIL;
		}
		ans[++l] = 0;
		printf("%s\n", ans + 1);
		continue;
FAIL:
		puts("impossible");
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 3852kb

input:

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

output:

impossible
()))())
)())())
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)