QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720737#9430. Left Shifting 2Alasco#AC ✓4ms7680kbC++141.3kb2024-11-07 13:52:192024-11-07 13:52:21

Judging History

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

  • [2024-11-07 13:52:21]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:7680kb
  • [2024-11-07 13:52:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n,p[500005],len[500005],sr,sl;
string s;
void __(){
    cin>>s;
    n=(int)s.size();
    int cnt=0;
    for(int i=0;i<=n-2;i++){
        if(s[i]!=s[i+1]){
            p[++cnt]=i;
        }
    }
    if(cnt==0){
        cout<<n/2<<"\n";
        return;
    }
    int tot=0;
    for(int i=1;i<=cnt-1;i++){
        len[++tot]=p[i+1]-p[i];
    }
    if(s[0]!=s[n-1]){
        len[++tot]=p[1]+1;
        len[++tot]=n-1-p[cnt];
    }else{
        len[++tot]=p[1]+n-p[cnt];
    }
    sl=0;
    sr=0;
    int ans=0;
    for(int i=1;i<=tot;i++){
        sr+=len[i]/2;
        ans+=len[i]/2;
    }
    // assert(sr==n);
    // if(tot==1){
    //     cout<<ans<<"\n";
    //     return;
    // }
    for(int i=1;i<=tot;i++){
        sr-=len[i]/2;
        for(int j=1;j<=len[i]-1;j++){
            ans=min(ans,sl+sr+j/2+(len[i]-j)/2);
            // cout<<"F"<<i<<" "<<j<<" "<<sl+sr+j/2+(len[i]-j)/2<<"\n";
        }
        sl+=len[i]/2;
    }
    cout<<ans<<"\n";
    // for(int i=1;i<=tot;i++){
    //     cout<<len[i]<<" ";
    // }
    // cout<<"\n";
    // for(int i=1;i<=cnt;i++){
    //     cout<<p[i]<<" ";
    // }
    // cout<<"\n";
}
int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr);
    int _;cin>>_;while(_--)__();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3708kb

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3664kb

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
1
0
6
1
2
0
1
0
0
4
1
2
4
3
1
3
2
3
1
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:

ok 5000 lines

Test #3:

score: 0
Accepted
time: 4ms
memory: 7552kb

input:

1
cbppzfsncqyzmuwrcvtxsciucxusskcjhaanwhqmyncytwhkubrvcqxgcehdxyewdyvpqjcmrnmlgrytrucexmmfulqbtfctehphmrzkosyvhtvjrromqncbgsjcwhmlqidkycaxyhsrduoxayntuhqubvboseeziwjvrfagsbvtxjjbexnajqapgxydwtztzbbdpoydnjipfizdfpmczgqvdmpvxbqubtygkfpdeonegfzsttirbhzkobbigwneyvtcxndfkljdvbbcfnadtfhgohfzqeidtgyandhnvb...

output:

18631

result:

ok single line: '18631'

Test #4:

score: 0
Accepted
time: 3ms
memory: 7680kb

input:

1
qokalgqjhyijyizyihdsiapbgvzxzevykavqmgqzrpjngciqcljsuplvpaziebmumatzvngwrhgsxrtcoiseihejwpewvosnrgvhoxluliuwixgxylazufebrwgfebazrkghgwbpqavehtnakmzqsetghmzoydwmeqvoplkyqngwrgktylrnaojpkvuwfsjbizedqwhfteyjobrglkhkeoxmxdgyuygawvdjhyakpkjchyxaqthrglcldevrzskdaotkbsbmnstrsxervdvmaylqxnwaecfmdszwedrdom...

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 2ms
memory: 5960kb

input:

1
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbyyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccceeeeeeeeeeeeeeeeeeeeezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

246800

result:

ok single line: '246800'

Test #6:

score: 0
Accepted
time: 2ms
memory: 5968kb

input:

1
yyyyyyyyyyyyyyyyyyyyyyyyhhhhhhhhaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnhhhhhhhhhhhhhhhhhhhhhhhiiiiiiiieeeeeeeeeesssssssbbbbbbbbbbiiiiiiiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaaaaaaaaaaaadccccckkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkc...

output:

242729

result:

ok single line: '242729'

Extra Test:

score: 0
Extra Test Passed