QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682327 | #9430. Left Shifting 2 | Lautisticyc | WA | 0ms | 3748kb | C++14 | 972b | 2024-10-27 15:00:56 | 2024-10-27 15:00:58 |
Judging History
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'