結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,284 KB
testcase_01 AC 7 ms
12,192 KB
testcase_02 AC 8 ms
12,248 KB
testcase_03 AC 8 ms
12,272 KB
testcase_04 AC 8 ms
12,216 KB
testcase_05 AC 38 ms
12,272 KB
testcase_06 AC 7 ms
12,260 KB
testcase_07 AC 38 ms
12,176 KB
testcase_08 AC 7 ms
12,240 KB
testcase_09 AC 20 ms
12,204 KB
testcase_10 AC 41 ms
12,172 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
12,272 KB
testcase_14 WA -
testcase_15 AC 7 ms
12,264 KB
testcase_16 AC 7 ms
12,288 KB
testcase_17 AC 8 ms
12,128 KB
testcase_18 AC 25 ms
12,248 KB
testcase_19 AC 34 ms
12,172 KB
testcase_20 AC 34 ms
12,260 KB
testcase_21 AC 33 ms
12,292 KB
testcase_22 AC 33 ms
12,240 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 = 0; $i <= $sum; $i++) {
		if (!$dp[$i]) continue;
		$dp[$i + $w] = true;
	}
}
echo $dp[$sum / 2] ? "possible" : "impossible";
?>
0