QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641459#7683. Hard Brackets Problemucup-team2526WA 0ms3832kbC++20994b2024-10-14 20:36:512024-10-14 20:36:53

Judging History

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

  • [2024-10-14 20:36:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-10-14 20:36:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

void GENSHEN_START() {
	string s;cin >> s;
	stack<char>sta;
	string ans = "";
	int cnt = 0;
	for (auto i : s) {
		if (sta.empty()) {
			if (i == ')') ans += i;
			else {
				sta.push(i);
				cnt++;
			}
		}
		else {
			if (i == '(') {
				sta.push(i);
				cnt++;
			}
			else {
				sta.pop();
				if (sta.empty()) {
					while (cnt) {
						ans += "()";
						cnt--;
					}
				} 
			}
		}
	}
	if (!sta.empty()) {
		cout << "impossible" << '\n';
	}
	else cout << ans << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int T = 1;
	cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3832kb

input:

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

output:

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

result:

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