結果

問題 No.29 パワーアップ
ユーザー d_nishiyama85d_nishiyama85
提出日時 2015-04-30 01:18:55
言語 PHP
(7.2.24)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 573 bytes
コンパイル時間 475 ms
使用メモリ 17,460 KB
最終ジャッジ日時 2023-02-07 22:58:49
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 13 ms
17,152 KB
testcase_01 AC 13 ms
17,204 KB
testcase_02 AC 13 ms
17,016 KB
testcase_03 AC 13 ms
17,104 KB
testcase_04 AC 14 ms
17,104 KB
testcase_05 AC 13 ms
17,308 KB
testcase_06 AC 13 ms
17,004 KB
testcase_07 AC 13 ms
17,244 KB
testcase_08 AC 12 ms
17,316 KB
testcase_09 AC 13 ms
17,144 KB
testcase_10 AC 13 ms
17,180 KB
testcase_11 AC 13 ms
17,200 KB
testcase_12 AC 13 ms
17,156 KB
testcase_13 AC 13 ms
17,380 KB
testcase_14 AC 13 ms
17,260 KB
testcase_15 AC 13 ms
17,360 KB
testcase_16 AC 13 ms
17,040 KB
testcase_17 AC 12 ms
17,252 KB
testcase_18 AC 13 ms
17,308 KB
testcase_19 AC 13 ms
17,280 KB
testcase_20 AC 12 ms
17,460 KB
testcase_21 AC 13 ms
17,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$N = trim(fgets(STDIN));

$list = [];
for ($i = 0; $i < $N; $i++) {
	$items = explode(" ", trim(fgets(STDIN)));
	foreach ($items as $item) {
		if (isset($list[$item])) {
			$list[$item]++;
		} else {
			$list[$item] = 1;
		}
	}
}

$powerup = 0;

while(true) {
	$plenty = array_filter($list, function($count) {
		return $count >= 2;
	});
	if (empty($plenty)) {
		break;
	}
	foreach ($list as $id => &$count) {
		if ($count >= 2) {
			$powerup++;
			$count -= 2;
		}
	}
}

unset($count);

$rest = array_sum($list);

$powerup += intval($rest / 4);

echo $powerup . "\n";
0