結果

問題 No.4 おもりと天秤
ユーザー ねずねず
提出日時 2018-01-28 11:49:01
言語 PHP
(8.3.4)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 367 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 12,092 KB
実行使用メモリ 12,360 KB
最終ジャッジ日時 2023-09-08 17:38:35
合計ジャッジ時間 1,430 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,316 KB
testcase_01 AC 7 ms
12,300 KB
testcase_02 AC 8 ms
12,168 KB
testcase_03 AC 7 ms
12,248 KB
testcase_04 AC 7 ms
12,256 KB
testcase_05 AC 24 ms
12,244 KB
testcase_06 AC 7 ms
12,192 KB
testcase_07 AC 25 ms
12,280 KB
testcase_08 AC 7 ms
12,304 KB
testcase_09 AC 20 ms
12,280 KB
testcase_10 AC 27 ms
12,192 KB
testcase_11 AC 7 ms
12,192 KB
testcase_12 AC 7 ms
12,220 KB
testcase_13 AC 8 ms
12,244 KB
testcase_14 AC 7 ms
12,268 KB
testcase_15 AC 7 ms
12,204 KB
testcase_16 AC 7 ms
12,360 KB
testcase_17 AC 7 ms
12,260 KB
testcase_18 AC 19 ms
12,288 KB
testcase_19 AC 23 ms
12,260 KB
testcase_20 AC 22 ms
12,272 KB
testcase_21 AC 22 ms
12,220 KB
testcase_22 AC 23 ms
12,172 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$n = trim(fgets(STDIN));
$weights = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($weights);
if ($sum % 2) {
	echo 'impossible';
	exit;
}
$dp = array_fill(0, $sum + 1, false);
$dp[0] = true;
foreach ($weights as $w) {
	for ($i = $sum; $i >= 0; $i--) {
		if (!$dp[$i]) continue;
		$dp[$i + $w] = true;
	}
}
echo $dp[$sum / 2] ? "possible" : "impossible";
?>
0