QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682297#9430. Left Shifting 2LautisticycWA 3ms3944kbC++14840b2024-10-27 14:53:072024-10-27 14:53:11

Judging History

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

  • [2024-10-27 14:53:11]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3944kb
  • [2024-10-27 14:53:07]
  • 提交

answer

/*
对于一坨颜色块(a)。
我们需要a/2的步数。
维护一下走了。
*/
#include<bits/stdc++.h>
using namespace std;
int cas,n,ans,now,lef,rig;
char s[1000010];
int main()
{
	scanf("%d",&cas);
	while(cas--)
	{
		scanf("%s",s+1);
		n=strlen(s+1);
		for(int i=1;i<=n;++i)	s[i+n]=s[i];
		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: 100
Accepted
time: 0ms
memory: 3748kb

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3944kb

input:

5000
lfpbavjsmppdppkfwnyfmbdhptdswsoulrbhyjh
cfliuqnynejgnxolzbdoztclzbozqomvioszk
eiivcoqoymonrqgrjdtkts
mdcvservaxcbioopfungsgkiftchwlmtbzqgaraovjknsgiegkvdbolmeunvrxrpscnf
ujeqtidwtoikkqtygo
llma
qjfvgwrdhaazejsfgilnpmmhkefndzvyon
kzwwpdpbrudqmwmjscllnnjyoepxophcoopvfepikouinuxx
vftculoorxskpkxoz...

output:

1
0
0
0
0
0
1
4
0
0
1
1
1
1
1
3
1
0
5
6
0
0
5
2
0
1
3
2
0
3
0
1
0
1
1
0
1
4
1
3
1
0
1
5
3
0
3
0
0
1
8
0
0
6
1
2
0
1
0
0
4
1
2
4
3
1
3
2
3
0
2
1
0
0
2
0
2
2
0
4
0
5
5
0
3
0
4
1
0
2
1
0
2
0
1
6
1
2
1
3
3
3
5
2
3
0
3
5
1
3
0
0
3
0
4
5
3
2
1
1
0
0
2
0
1
1
3
3
3
1
2
0
1
1
4
3
1
3
1
1
1
2
0
1
2
0
4
0
1
1
...

result:

wrong answer 52nd lines differ - expected: '1', found: '0'