結果

問題 No.29 パワーアップ
ユーザー d_nishiyama85
提出日時 2015-04-30 01:18:55
言語 PHP
(843.2)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 573 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 30,976 KB
実行使用メモリ 31,532 KB
最終ジャッジ日時 2024-07-05 16:53:42
合計ジャッジ時間 3,156 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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