QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#279331#7894. Many Many HeadssuperguymjWA 5ms6036kbC++14966b2023-12-08 16:11:422023-12-08 16:11:42

Judging History

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

  • [2023-12-08 16:11:42]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:6036kb
  • [2023-12-08 16:11:42]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid ((l+r)>>1)

using namespace std;
const int N=1000005;
char s[N];
int n,a[N];

bool check(int l,int r)
{
	if(l>r) return 0;
	rep(i,l,mid-1) if(a[i]==a[i+1]) return 0;
	rep(i,mid+1,r-1) if(a[i]==a[i+1]) return 0;
	return 1;
}

void solve()
{
	scanf("%s",s+1),n=strlen(s+1);
	vector <int> stk;
	rep(i,1,n)
	{
		int c=(s[i]=='(' || s[i]==')');
		a[i]=c;
		if(!stk.empty() && a[stk.back()]==c)
		{
			if(c) s[i]=')';
			else s[i]=']';
			stk.pop_back();
		}
		else
		{
			if(c) s[i]='(';
			else s[i]='[';
			stk.push_back(i);
		}
	}
	rep(i,1,n-1) if(s[i]==')' && s[i+1]=='(')
		return puts("No"),void();
	rep(i,1,n-1) if(s[i]==']' && s[i+1]=='[')
		return puts("No"),void();
	if(check(1,n) || check(3,n) || check(1,n-2)) 
		return puts("Yes"),void();
	puts("No");
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5752kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
No
Yes
No
Yes
No

result:

ok 6 token(s): yes count is 3, no count is 3

Test #2:

score: 0
Accepted
time: 0ms
memory: 5812kb

input:

2
(([([[([
]]))])]])]

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 6036kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
No
No
No
No
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No...

result:

wrong answer expected YES, found NO [22nd token]