QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682327#9430. Left Shifting 2LautisticycWA 0ms3748kbC++14972b2024-10-27 15:00:562024-10-27 15:00:58

Judging History

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

  • [2024-10-27 15:00:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3748kb
  • [2024-10-27 15:00:56]
  • 提交

answer

/*
对于一坨颜色块(a)。
我们需要a/2的步数。
维护一下走了。
*/
#include<bits/stdc++.h>
using namespace std;
int cas,n,ans,now,lef,rig;
char s[1000010];
bool flag;
int main()
{
	scanf("%d",&cas);
	while(cas--)
	{
		scanf("%s",s+1);
		n=strlen(s+1);
		flag=1;
		for(int i=1;i<=n;++i)
		{
			s[i+n]=s[i];
			if(i>1&&s[i]==s[i-1])	flag=0;
		}
		if(!flag)
		{
			printf("%d\n",n/2);
			continue;
		}
		now=0;
		for(int i=1;i<n;++i)
		{
			if(s[i]==s[i+1])
			{
				++now;
				++i;
			}
		}
		lef=1;
		while(s[lef+1]==s[1]&&lef<n)	++lef;
		rig=1;
		while(s[n-rig]==s[n]&&rig<n)	++rig;
		ans=now;
		for(int i=2;i<=n;++i)
		{
			now-=(lef/2);
			--lef;
			if(!lef)
			{
				lef=1;
				while(s[lef+i]==s[i]&&lef<n)	++lef;
			}
			else	now+=(lef/2);
			if(s[i+n-1]==s[i+n-2])
			{
				++rig;
				if(rig%2==0)	++now;
			}
			else	rig=1;
			ans=min(ans,now);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
abccbbbbd
abcde
x

output:

4
0
0

result:

wrong answer 1st lines differ - expected: '2', found: '4'