QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395391#7683. Hard Brackets Problemzzuqy#WA 13ms3872kbC++14573b2024-04-21 14:03:422024-04-21 14:03:43

Judging History

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

  • [2024-04-21 14:03:43]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3872kb
  • [2024-04-21 14:03:42]
  • 提交

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] = ')';
			i--;
			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: 3816kb

input:

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

output:

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

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 3872kb

input:

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

output:

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

result:

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