QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#779682 | #9430. Left Shifting 2 | syhhh1 | WA | 12ms | 3556kb | C++17 | 779b | 2024-11-24 21:09:22 | 2024-11-24 21:09:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+10;
char a[N];
signed main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int n=s.length();
int ans=0;
vector<pair<char,int>>v;
int k=0;
for(int i=0;i<n;)
{
int j=i;
while(s[j]==s[i])j++;
v.push_back({s[i],j-i});
if((j-i)%2==0)k++;
ans+=(j-i)/2;
i=j;
}
bool fg=false;
int sz=v[v.size()-1].second;
for(int i=0;i<v.size();i++)
{
if(v[i].first!=s[n-1]&&v[i].second%2==0&&k>=2)fg=true;
if(v[i].first==s[n-1])
{
if(k>=2&&(v[i].second+sz)%2)fg=true;
if(k>=2&&(v[i].second+sz)%2==0)fg=true;
}
}
if(fg)cout<<ans-1<<endl;
else cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
3 abccbbbbd abcde x
output:
2 0 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 3524kb
input:
5000 lfpbavjsmppdppkfwnyfmbdhptdswsoulrbhyjh cfliuqnynejgnxolzbdoztclzbozqomvioszk eiivcoqoymonrqgrjdtkts mdcvservaxcbioopfungsgkiftchwlmtbzqgaraovjknsgiegkvdbolmeunvrxrpscnf ujeqtidwtoikkqtygo llma qjfvgwrdhaazejsfgilnpmmhkefndzvyon kzwwpdpbrudqmwmjscllnnjyoepxophcoopvfepikouinuxx vftculoorxskpkxoz...
output:
1 0 1 1 1 1 1 4 1 0 1 1 1 1 2 3 1 1 5 6 1 1 5 2 1 1 3 1 0 3 1 1 0 1 1 0 1 4 2 3 1 1 1 5 3 1 3 1 0 1 7 1 1 6 1 2 1 2 0 1 4 1 2 4 3 1 3 2 3 1 2 1 1 1 2 1 2 2 1 4 1 5 5 1 3 1 4 1 0 2 1 1 3 0 1 6 1 2 1 3 3 3 5 2 3 1 3 5 2 3 1 1 3 1 4 5 3 2 1 1 0 1 2 1 2 1 2 3 3 1 2 1 1 1 4 2 1 3 1 1 1 2 1 1 2 1 4 1 2 1 ...
result:
wrong answer 3rd lines differ - expected: '0', found: '1'