結果

問題 No.672 最長AB列
ユーザー kanpurin002kanpurin002
提出日時 2018-11-14 01:19:57
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 551 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 28,468 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-26 01:00:06
合計ジャッジ時間 6,010 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
8,752 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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