QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661729#7683. Hard Brackets ProblemjiangtaoWA 16ms3640kbC++201.2kb2024-10-20 17:48:272024-10-20 17:48:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-20 17:48:28]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3640kb
  • [2024-10-20 17:48:27]
  • 提交

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 = max(0ll, now - 1);
    		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: 0ms
memory: 3576kb

input:

3
((()))
(
)))()

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 16ms
memory: 3640kb

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)