結果

問題 No.920 あかあお
ユーザー seaside0002seaside0002
提出日時 2019-12-30 13:42:42
言語 PHP
(8.3.4)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 31,892 KB
実行使用メモリ 32,624 KB
最終ジャッジ日時 2024-04-25 16:57:41
合計ジャッジ時間 2,747 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
32,532 KB
testcase_01 AC 39 ms
32,400 KB
testcase_02 AC 39 ms
32,532 KB
testcase_03 AC 40 ms
32,528 KB
testcase_04 AC 39 ms
32,528 KB
testcase_05 AC 40 ms
32,400 KB
testcase_06 AC 40 ms
32,532 KB
testcase_07 AC 39 ms
32,276 KB
testcase_08 AC 39 ms
32,404 KB
testcase_09 AC 38 ms
32,268 KB
testcase_10 AC 41 ms
32,400 KB
testcase_11 AC 40 ms
32,528 KB
testcase_12 AC 38 ms
32,528 KB
testcase_13 AC 37 ms
32,624 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
list($r, $b, $w) = explode(" ", trim(fgets(STDIN)));

$balls = array(
	'red' => $r,
	'blue' => $b,
	'white' => $w,
	'violet' => 0
);

makeViolet($balls);

echo $balls['violet'];


function makeViolet(&$balls): void{
	// 1ケもつくれない 
	if(($balls['red'] == 0 or $balls['blue'] == 0) and ($balls['white'] == 0)){
		return;
	}
	
	// 少ない方に全部足してそれが答え
	if(abs($balls['red'] - $balls['blue']) > $balls['white'] ){
		// 宇宙船演算子で比較
		$target = $balls['red'] <=> $balls['blue'];
		
		if($target == 1){
			$target = 'blue';
		}else if($target == -1){
			$target = 'red';
		}else{
			return;
		}

		$balls['violet'] = $balls["$target"] + $balls['white'];
			
		return;
	} 
		
	// 全部足して半分にする
	if(abs($balls['red'] - $balls['blue']) <= $balls['white'] ){
		$violets = ($balls['red'] + $balls['blue'] + $balls['white']) / 2;
		$balls['violet'] = floor($violets);
	}
}







0