QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#643387 | #7683. Hard Brackets Problem | ospoasa | WA | 14ms | 3860kb | C++14 | 952b | 2024-10-15 20:57:38 | 2024-10-15 20:57:39 |
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 << "impossible" << '\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: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 3860kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())()) )()()()( impossible ((())() impossible )()))())) impossible impossible ()((()( (()())() ())(()))( (())(()) impossible impossible ()((())( ()))()))( ()((())( impossible ()))(() (()(() ())((( impossible (()(() impossible impossible impossible impossible impossible ())(()))( impossi...
result:
wrong answer the result string is incorrect (test case 2)