QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661721#7683. Hard Brackets ProblemjiangtaoWA 17ms3828kbC++201.1kb2024-10-20 17:46:272024-10-20 17:46:27

Judging History

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

  • [2024-10-20 17:46:27]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3828kb
  • [2024-10-20 17:46: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--;
    		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)