QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661810#7683. Hard Brackets ProblemjiangtaoWA 8ms3856kbC++201.2kb2024-10-20 18:18:502024-10-20 18:18:50

Judging History

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

  • [2024-10-20 18:18:50]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3856kb
  • [2024-10-20 18:18:50]
  • 提交

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 = 1e6 + 5, M = 1e9 + 7, mod = 998244353;
#define YES {cout << "Yes" << endl; return ;}
#define NO {cout << "No" << endl; return ;}
char st[N];
char ans[N];
int top, now;
void solve(){
	top = 0;
	now = 0;
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++){
    	char c = s[i];
    	if (c == '(') {
    		st[++top] = c;
    		ans[++now] = '(';
    	}
    	else {
    		if (top == 0) {
    			ans[++now] = ')';
    		}else if (top != n - i){
    			ans[++now] = ')';
    			top--;
    		}else{
    			top--;
    		}
    	}
    }
    if (top) cout << "impossible\n";
    else {
    	cout << ans + 1 << "\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: 3572kb

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 8ms
memory: 3856kb

input:

100000
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
(()())())
())(()))()
(())(())))
))))(()(()
()))(())((
()((())())
()))()))()
()((())())
()()))((()
()))(()))
(()(())))
())((()))
())()((())
(()(())))
()(((()())
))))())))(
((((()()()
(()(...

output:

impossible
()())())))
)()()()())
impossible
((())()))(
impossible
)()))())))
impossible
impossible
()((()((()
(()())()))
())(()))()
(())(())))
impossible
impossible
()((())(((
()))()))((
()((())(((
impossible
()))(())))
(()(()))))
())((())))
impossible
(()(()))))
impossible
impossible
impossible
imp...

result:

wrong answer the output is too long (test case 2)