結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,248 KB
testcase_01 AC 7 ms
12,280 KB
testcase_02 AC 8 ms
12,272 KB
testcase_03 WA -
testcase_04 AC 8 ms
12,208 KB
testcase_05 AC 50 ms
24,028 KB
testcase_06 AC 8 ms
12,308 KB
testcase_07 AC 52 ms
24,008 KB
testcase_08 AC 8 ms
12,284 KB
testcase_09 AC 37 ms
40,936 KB
testcase_10 AC 54 ms
24,060 KB
testcase_11 AC 7 ms
12,216 KB
testcase_12 AC 7 ms
12,352 KB
testcase_13 AC 7 ms
12,344 KB
testcase_14 AC 7 ms
12,312 KB
testcase_15 AC 7 ms
12,196 KB
testcase_16 WA -
testcase_17 AC 7 ms
12,276 KB
testcase_18 AC 37 ms
24,032 KB
testcase_19 AC 46 ms
23,964 KB
testcase_20 AC 46 ms
24,060 KB
testcase_21 AC 44 ms
24,064 KB
testcase_22 AC 45 ms
24,036 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

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