QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#771249#7683. Hard Brackets ProblemxsdgpWA 10ms3728kbC++20725b2024-11-22 11:07:202024-11-22 11:07:21

Judging History

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

  • [2024-11-22 11:07:21]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3728kb
  • [2024-11-22 11:07:20]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
string s;
bool vis[1000005];
void solve()
{
	cin>>s;
	int cnt=0;
	for(int i=0;i<s.size();i++)
		vis[i]=0;
	for(int i=0;i<s.size();i++)
		if(s[i]=='(')cnt++;
	if(cnt<=s.size()-cnt)
	{
		cnt=0;
		for(int i=0;i<s.size();i++)
			if(s[i]=='(')cnt++;
			else if(cnt)
			{
				vis[i]=1;
				cnt--;
			}
		for(int i=s.size()-1;i>=0;i--)
			if(s[i]==')'&&vis[i])s.pop_back();
			else break;
		cout<<s<<endl;
	}
	else cout<<"impossible"<<endl;
		
}
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T=1;
	cin>>T;
	while(T--)solve();
	return 0;
}
/*
3
((()))
(
)))()

(()(())))
*/

詳細信息

Test #1:

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

input:

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

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 3728kb

input:

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

output:

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

result:

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