QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628895 | #9430. Left Shifting 2 | Zhou_JK | WA | 2ms | 3556kb | C++23 | 844b | 2024-10-10 23:00:14 | 2024-10-10 23:00:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
int n;
string s;
void solve()
{
cin>>s;
n=s.size();
int len=0;
for(int i=0;i<n;i++)
if(s[i]==s[0]) len++;
else break;
if(len==n)
{
cout<<n/2<<"\n";
return;
}
string t;
for(int i=len;i<n;i++)
t+=s[i];
for(int i=0;i<len;i++)
t+=s[i];
s=t;
int sum=0,del=0;
for(int i=0,j=0;i<n;i=j)
{
while(j<n&&s[i]==s[j]) j++;
int len=j-i;
if(len>1) sum+=len/2;
if(len%2==0&&len>2) del=max(del,1);
}
int ans=sum-del;
cout<<ans<<"\n";
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
3 abccbbbbd abcde x
output:
2 0 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3556kb
input:
5000 lfpbavjsmppdppkfwnyfmbdhptdswsoulrbhyjh cfliuqnynejgnxolzbdoztclzbozqomvioszk eiivcoqoymonrqgrjdtkts mdcvservaxcbioopfungsgkiftchwlmtbzqgaraovjknsgiegkvdbolmeunvrxrpscnf ujeqtidwtoikkqtygo llma qjfvgwrdhaazejsfgilnpmmhkefndzvyon kzwwpdpbrudqmwmjscllnnjyoepxophcoopvfepikouinuxx vftculoorxskpkxoz...
output:
2 0 1 1 1 1 2 5 1 0 2 2 2 2 2 4 2 1 6 7 1 1 6 3 1 2 4 3 1 4 1 2 1 1 2 1 2 5 2 4 2 1 2 6 4 1 4 1 0 2 9 1 1 7 2 3 1 2 1 1 5 2 3 5 4 2 4 2 4 1 3 2 1 1 3 1 3 3 1 5 1 6 6 1 4 1 5 2 0 3 2 1 3 1 2 7 2 3 2 4 4 4 5 3 4 1 4 6 2 4 1 1 4 1 5 6 4 3 1 2 0 1 3 1 2 2 4 4 4 2 3 1 2 2 5 4 2 4 2 2 2 3 1 2 3 1 5 1 2 2 ...
result:
wrong answer 1st lines differ - expected: '1', found: '2'