QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678990#7683. Hard Brackets ProblemDisplace_#WA 56ms3584kbC++14644b2024-10-26 16:36:292024-10-26 16:36:29

Judging History

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

  • [2024-10-26 16:36:29]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:3584kb
  • [2024-10-26 16:36:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+86;
int T;
string s;

int main()
{
	cin>>T;
	while(T--)
	{
		string as;
		cin>>s;
		int sm=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='(') sm++;
			if(sm&&s[i]==')') sm--;
		}
		if(sm)
		{
			cout<<"impossible"<<endl;
			continue;
		}
		int i=0,j=0;
		while(i<s.size())
		{
			if(s[i]==')')
			{
				if(as[j]=='(') i++;
				else as[++j]=s[i],i++;
			}
			else if(s[i]=='(')
			{
				if(s[i+1]=='(') as[++j]=s[i],i++; 
				else as[++j]=s[i],i+=2;
			}
			else i++;
		}
		for(int k=1;k<=j;k++) cout<<as[k];
		cout<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

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

input:

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

output:

impossible
(((
)((((
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)