QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#654325#7683. Hard Brackets ProblemSound_MediumWA 11ms3624kbC++23553b2024-10-18 21:24:482024-10-18 21:24:57

Judging History

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

  • [2024-10-18 21:24:57]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3624kb
  • [2024-10-18 21:24:48]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;

void solve () {
	string s;
	cin>>s;
	string ans;
	int cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			cnt++;
			ans.push_back('(');
		}
		else if(s[i]==')'){
			if(cnt>0){
				cnt--;
			}else{
				ans.push_back(')');
			}
		}
	}
	if(cnt){
		cout<<"impossible\n";
	}else{
		cout<<ans<<endl;
	}
}
signed main () {
	int T = 1; 
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin>>T;
	while (T --) solve ();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3584kb

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)