QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#643385 | #7683. Hard Brackets Problem | ospoasa | WA | 1ms | 3856kb | C++14 | 952b | 2024-10-15 20:56:36 | 2024-10-15 20:56:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char stk[N];
void solve()
{
int top = 0;
string K, ans;
cin >> K;
int n = K.size();
K = ' ' + K;
int cnt = 0;
for(int i = 1; i <= n; i++) {
if(K[i] == '(') {
for(int j = 1; j <= cnt; j++) {
ans += ')';
}
ans += '(';
stk[++top] = '(';
cnt = 0;
}
else {
if(stk[top] == '(') top--, cnt++;
else {
ans += ')';
stk[++top] = ')';
}
}
}
for(int i = top; i >= 1; i--) {
if(stk[i] == '(') {
cout << "impossable" << '\n';
return;
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3856kb
input:
3 ((())) ( )))()
output:
((( impossable )))(
result:
wrong answer the output is too long (test case 2)