QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687733#9430. Left Shifting 2Akoasm_XWA 1ms3900kbC++201.3kb2024-10-29 20:55:162024-10-29 20:55:16

Judging History

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

  • [2024-10-29 20:55:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3900kb
  • [2024-10-29 20:55:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
// #define int long long
typedef long long LL;

inline int read(){
	int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; } 
    while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; } 
    return x * f ;
}

const int maxn = 1e6+20;
int n;
int ans = 0;
int cnt[2][maxn];
char S[maxn];

void solve(){
    scanf("%s",S+1);
    n = strlen(S+1);
    for(int i=1;i<=n;i++) S[i+n] = S[i];
    // printf("%s\n",S+1);
    for(int i=2;i<=2*n;i++){
        cnt[1][i] = cnt[1][i-1];
        if(S[i]==S[i-1]){
            cnt[1][i]++;
            i++;
            cnt[1][i] = cnt[1][i-1];
        }
    }
    for(int i=3;i<=2*n;i++){
        cnt[0][i] = cnt[0][i-1];
        if(S[i]==S[i-1]){
            cnt[0][i]++;
            i++;
            cnt[0][i] = cnt[0][i-1];
        }
    }
    int ans = n;
    // cout<<cnt[0][6+n-1]<<' '<<cnt[0][6]<<endl;
    for(int i=1;i+n-1<=2*n;i+=2) ans = min(ans,cnt[1][i+n-1] - cnt[1][i]);
    for(int i=2;i+n-1<=2*n;i+=2) ans = min(ans,cnt[0][i+n-1] - cnt[0][i]);
    printf("%d\n",ans);
}

signed main(){
	// freopen("1.txt","r",stdin);
	int T = 1;
	T = read();
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3900kb

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3828kb

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
0
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
1
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
0
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 34th lines differ - expected: '1', found: '0'