QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661721 | #7683. Hard Brackets Problem | jiangtao | WA | 17ms | 3828kb | C++20 | 1.1kb | 2024-10-20 17:46:27 | 2024-10-20 17:46:27 |
Judging History
answer
// Problem: G. Hard Brackets Problem
// Contest: Codeforces - 2023 China Collegiate Programming Contest (CCPC) Guilin Onsite (The 2nd Universal Cup. Stage 8: Guilin)
// URL: https://codeforces.com/gym/104768/problem/G
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Begin:2024-10-20 17:06:45
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5, M = 1e9 + 7, mod = 998244353;
#define YES {cout << "Yes" << endl; return ;}
#define NO {cout << "No" << endl; return ;}
void solve(){
string s; cin >> s;
int now = 0;
int you = 0;
string ans = "";
for (auto x : s){
if (x == '(') {
now++;
ans = ans + '(';
you++;
}
else {
now--;
if (you == 0){
ans = ans + ')';
}else{
you--;
}
}
}
if (now > 0) {
cout << "impossible\n";
return ;
}
cout << ans << "\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int ___ = 1;
cin >> ___;
while (___--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 17ms
memory: 3828kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
()(((( (()()) )(((( ()(((( (((() )((())( )())())) )))))(((( impossible ((((( (((() ()(()( (((()) ))))(((( ())(((( ((((( ())())( ((((( (())((( ())(() (((() ()((( ()(((( (((() impossible ))))()))( impossible impossible impossible ()(()( ))((((( (((()( impossible )))(()( (()()( ((()() (((() impossible ...
result:
wrong answer the result string is incorrect (test case 1)