QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645883#7683. Hard Brackets ProblemE_REMALWA 0ms3612kbC++141.2kb2024-10-16 20:20:062024-10-16 20:20:11

Judging History

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

  • [2024-10-16 20:20:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-10-16 20:20:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,l,r;
string s;
int lef,righ;
int loc;//¼Ç¼¹â±ê×îºóµÄλÖÃ
vector <int> ans;
bool b;
int main()
{
	cin>>n;
	while(n--) {
		cin>>s;
		loc=0;
		righ=0;
		lef=0;
		b=1;
		ans.clear();
		for(int i=s.length()-1;i=0;i--) {
			if(i<s.length()-1){
				if(s[i]=='('&&s[i+1]==')'){
						if(loc==0) loc=i;
						else b=0;
				}
			}
			if(s[i]=='(') lef=1;
			else righ=1;
		}
		if(loc==0&&lef==0) {
			for(int i=0;i<s.length();i++) ans.push_back(1);
		}
		else if(b==1) {
			righ=0;
			lef=0;
			l=loc;
			r=loc+1;
			for(int i=0;i<=l;i++) {
				if(s[i]=='(') {
					lef++;
				}
			}
			for(int i=r;i<s.length();i++) {
				if(s[i]==')') righ++;
				if(s[i]=='(') {
					b=0;
					break;
				}
			}
			if(lef>righ) b=0;
			l=0;
			r=s.length()-1;
			while(l<=r) {
			if(s[r]=='(') {
				b=0;
				break;
			}
			if(s[l]=='(' && s[r]==')' ) {
				ans.push_back(0);
				l++;
				r--;
			}
			else if(s[l]==')') {
				ans.push_back(1);
				l++;
			}
		}
		}
		if(b==0) cout<<"impossible"<<endl;
		else {
			for(int i=0;i<ans.size();i++) {
				if(ans[i]==0) cout<<'(';
				else cout<<')';
			}
			cout<<endl;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

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

output:

))))))
)
)))))

result:

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