QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466758#7683. Hard Brackets Problemyurongyi#WA 12ms3644kbC++14640b2024-07-08 09:29:502024-07-08 09:29:50

Judging History

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

  • [2024-07-08 09:29:50]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3644kb
  • [2024-07-08 09:29:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
string s, ans;
int cnt1 = 0, cnt2 = 0;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int Cases;
	cin >> Cases;
	while(Cases--){
		cin >> s;
		ans.clear();
		cnt1 = cnt2 = 0;
		for(auto c : s){
			if(c == '('){
				while(cnt2){
					ans.push_back(')');
					cnt2--;
				}
				cnt1++;
			}
			else{
				if(cnt1){
					ans.push_back('(');
					cnt1--, cnt2++;
				}
				else
					ans.push_back(')');
			}
//			cout << cnt1 << endl;
		}
		if(cnt1)
			cout << "impossible\n";
		else
			cout << ans << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 3620kb

input:

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

output:

impossible
()())())
)()()()(
impossible
(())(()
impossible
)()))()))
impossible
impossible
()()(((
()(())()
())(()))(
(())(())
impossible
impossible
()(())((
()))()))(
()(())((
impossible
()))(()
()((()
())(((
impossible
()((()
impossible
impossible
impossible
impossible
impossible
())(()))(
impossi...

result:

wrong answer the result string is incorrect (test case 2)