結果

問題 No.672 最長AB列
ユーザー kanpurin002
提出日時 2018-11-14 01:19:57
言語 C
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 551 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 29,824 KB
実行使用メモリ 15,560 KB
最終ジャッジ日時 2024-12-24 13:33:56
合計ジャッジ時間 31,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>

int main(){
	char str[200001];
	int countA,countB,i,j,k,len,max=0;
	scanf("%s",str);
	len=strlen(str);
	for (i=2;i<=len;i+=2) {
		countA=countB=0;
		for (k=0;k<i;k++) {
			str[k]=='A'?countA++:countB++;
		}
		if (countA==countB) max=i;
		for (j=i;j<=len;j++) {
			if (str[j-i]=='A'&&str[j]=='B') countA--,countB++;
			else if (str[j-i]=='B'&&str[j]=='A') countA++,countB--;
			if (countA==countB) {
				max=i;break;
			}
		}
	}
	printf("%d",max);
	//printf("%d",strlen(str));
	return 0;
}
0