結果

問題 No.29 パワーアップ
ユーザー jake_tarojake_taro
提出日時 2015-09-05 21:35:11
言語 PHP
(8.3.4)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 821 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 18,736 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2023-09-26 09:13:38
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,916 KB
testcase_01 AC 15 ms
18,768 KB
testcase_02 AC 15 ms
18,776 KB
testcase_03 AC 15 ms
18,860 KB
testcase_04 AC 15 ms
18,892 KB
testcase_05 AC 15 ms
18,764 KB
testcase_06 AC 15 ms
18,644 KB
testcase_07 AC 15 ms
18,860 KB
testcase_08 AC 15 ms
18,888 KB
testcase_09 AC 15 ms
18,744 KB
testcase_10 AC 15 ms
18,652 KB
testcase_11 AC 15 ms
18,924 KB
testcase_12 AC 15 ms
18,768 KB
testcase_13 AC 16 ms
18,756 KB
testcase_14 AC 15 ms
18,768 KB
testcase_15 AC 15 ms
18,880 KB
testcase_16 AC 15 ms
18,644 KB
testcase_17 AC 15 ms
18,932 KB
testcase_18 AC 15 ms
18,756 KB
testcase_19 AC 16 ms
18,900 KB
testcase_20 AC 16 ms
18,764 KB
testcase_21 AC 15 ms
18,828 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$n = (int)trim(fgets(STDIN)); //敵を倒す回数

//N回分、敵を倒した時にもらえる3つのアイテムの配列
for($i = 0; $i < $n; $i++){
	$abc[] = explode(" ", trim(fgets(STDIN)));
}

//test
# print_r($abc);

for($j = 0; $j < $n; $j++){
	for($k = 0; $k < 3; $k++){
		$all[] = $abc[$j][$k];
	}
}
//ソート
sort($all);

$count = array_count_values($all);

$count_arr = array_values($count);

$total_powerup = 0;
$powerup_1 = 0;
for($h = 0; $h < count($count_arr); $h++){
	//同じ数字が2つあればパワーアップできる
	$powerup = floor($count_arr[$h] / 2);
	$total_powerup += $powerup;
	
	//4つのアイテムが集まればパワーアップできる
	if((($count_arr[$h]) % 2) == 1){
		$powerup_1++; 
	}
}
$amari = floor($powerup_1 / 4);
echo $amari + $total_powerup, PHP_EOL;
0