結果

問題 No.672 最長AB列
ユーザー dong_fengdong_feng
提出日時 2018-04-19 23:32:05
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 1,016 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 18,732 KB
実行使用メモリ 45,736 KB
最終ジャッジ日時 2023-09-10 04:44:11
合計ジャッジ時間 4,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
23,412 KB
testcase_01 AC 17 ms
18,836 KB
testcase_02 AC 17 ms
18,832 KB
testcase_03 AC 17 ms
18,852 KB
testcase_04 AC 16 ms
18,836 KB
testcase_05 AC 16 ms
18,688 KB
testcase_06 AC 16 ms
18,940 KB
testcase_07 AC 17 ms
18,952 KB
testcase_08 AC 16 ms
18,876 KB
testcase_09 AC 36 ms
41,132 KB
testcase_10 AC 42 ms
41,024 KB
testcase_11 AC 41 ms
41,216 KB
testcase_12 TLE -
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;
$serchTimes *= 2;

//処理
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