QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682297 | #9430. Left Shifting 2 | Lautisticyc | WA | 3ms | 3944kb | C++14 | 840b | 2024-10-27 14:53:07 | 2024-10-27 14:53:11 |
Judging History
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'