QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#641449 | #7683. Hard Brackets Problem | ucup-team2526 | WA | 14ms | 3816kb | C++20 | 993b | 2024-10-14 20:32:38 | 2024-10-14 20:32:40 |
Judging History
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;
}
详细
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: 14ms
memory: 3560kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
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)