QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287188 | #7683. Hard Brackets Problem | Detach | WA | 20ms | 3484kb | C++17 | 1.1kb | 2023-12-19 22:20:08 | 2023-12-19 22:20:09 |
Judging History
answer
#include <bits/stdc++.h>
// #include <algorithm>
// #include <queue>
// #include <map>
// #include <iostream>
// #include <string>
// #include <set>
#define endl '\n'
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using i128 = __int128_t;
using ULL = unsigned long long;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, N = 1e6 + 5;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
void solve()
{
string s;
cin >> s;
int n = s.size(), cnt[2] = {0};
for(int i = 0; i < n; i ++ )
{
int k;
if(s[i] == '(') cnt[0] ++ ;
else cnt[1] ++ ;
}
if(cnt[0] > cnt[1])
{
cout << "impossible" << endl;
}
else
{
int now = 0;
for(int i = 0; i < n; i ++ )
{
cout << s[i];
if(s[i] == '(') cnt[0] -- ;
else cnt[1] -- ;
if(!cnt[0]) break;
}
cout << endl;
}
}
int main()
{
// freopen("galactic.in", "r", stdin);
ios::sync_with_stdio(false), cin.tie(nullptr);
int T = 1;
cin >> T;
while(T -- )
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3484kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 20ms
memory: 3484kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
())(()()( ()())( )()()()( ())()(())( ((())( )(())()))( )()))( )))))(((( impossible ()((()( (()())( ())(()))( (())(( ))))(()(( ()))(())(( ()((())( ()))()))( ()((())( ()()))((( ()))(( (()(( ())((( ())()((( (()(( impossible ))))())))( impossible impossible impossible ())(()))( ))()(()(( (())()())( impo...
result:
wrong answer the result string is incorrect (test case 1)