結果

問題 No.672 最長AB列
ユーザー dong_fengdong_feng
提出日時 2018-04-19 23:31:18
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 18,524 KB
実行使用メモリ 60,460 KB
最終ジャッジ日時 2023-09-10 04:44:06
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
18,964 KB
testcase_02 AC 16 ms
18,780 KB
testcase_03 AC 16 ms
18,648 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 36 ms
41,208 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

//取得
$charList = array_diff(str_split(fgets(STDIN), 1),array(PHP_EOL, "\n", "\r"));
$listCount = count($charList);

//調べる回数を減らすために調べる最長文字数を決定する
$count = 0;
for($i=0;$i<$listCount;$i++){
	if($charList[$i] == 'A') $count++;
}
$serchTimes = ($count<$listCount/2)?
			$count:$listCount-$count;

//処理
for($i=$serchTimes; $i>0; $i--){//文字列を切る長さのループ
	if($i%2==0){	//奇数文字の文字列はやる意味がない
		for($j=0; $j<($listCount-$i+1); $j++){	//文字列のスタート位置を決めるループ
			$count = 0; //Aの個数をカウントしてくれる
			for($k=$j; $k<$j+$i; $k++){	//切り出した文字列を回すループ
				if($charList[$k]=='A') {
					$count ++;
				}
//				echo $charList[$k];
			}
//			echo PHP_EOL;
			if($count == $i/2) {	//Aの個数がちょうど半分なら出力して終わり
//				echo $j.PHP_EOL;
				echo $i.PHP_EOL;
				exit;
			}
		}
	}
}

echo "0".PHP_EOL;
0