結果

問題 No.4 おもりと天秤
ユーザー ねずねず
提出日時 2018-01-28 11:14:28
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 373 bytes
コンパイル時間 34 ms
コンパイル使用メモリ 12,120 KB
実行使用メモリ 12,392 KB
最終ジャッジ日時 2023-08-28 12:58:12
合計ジャッジ時間 1,382 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,300 KB
testcase_01 AC 7 ms
12,244 KB
testcase_02 WA -
testcase_03 AC 8 ms
12,228 KB
testcase_04 AC 9 ms
12,244 KB
testcase_05 AC 43 ms
12,252 KB
testcase_06 WA -
testcase_07 AC 41 ms
12,312 KB
testcase_08 AC 7 ms
12,276 KB
testcase_09 AC 20 ms
12,224 KB
testcase_10 AC 45 ms
12,260 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 7 ms
12,252 KB
testcase_17 AC 7 ms
12,284 KB
testcase_18 WA -
testcase_19 AC 37 ms
12,284 KB
testcase_20 AC 37 ms
12,228 KB
testcase_21 AC 35 ms
12,176 KB
testcase_22 AC 37 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;
for ($i = 0; $i < $n; $i++) {
	for ($j = 0; $j <= $sum; $j++) {
		if (!$dp[$j]) continue;
		$dp[$j + $weights[$i]] = true;
	}
}
echo $dp[0] ? "possible" : "impossible";
?>
0