結果

問題 No.4 おもりと天秤
ユーザー snicmakinosnicmakino
提出日時 2017-04-26 17:33:50
言語 PHP
(8.3.4)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 451 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 12,080 KB
実行使用メモリ 12,320 KB
最終ジャッジ日時 2023-09-08 17:24:30
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
12,304 KB
testcase_01 AC 8 ms
12,228 KB
testcase_02 AC 8 ms
12,232 KB
testcase_03 AC 7 ms
12,280 KB
testcase_04 AC 8 ms
12,252 KB
testcase_05 AC 24 ms
12,232 KB
testcase_06 AC 7 ms
12,276 KB
testcase_07 AC 24 ms
12,296 KB
testcase_08 AC 8 ms
12,224 KB
testcase_09 AC 18 ms
12,272 KB
testcase_10 AC 26 ms
12,300 KB
testcase_11 AC 7 ms
12,240 KB
testcase_12 AC 7 ms
12,304 KB
testcase_13 AC 7 ms
12,296 KB
testcase_14 AC 7 ms
12,224 KB
testcase_15 AC 7 ms
12,264 KB
testcase_16 AC 7 ms
12,224 KB
testcase_17 AC 7 ms
12,320 KB
testcase_18 AC 17 ms
12,284 KB
testcase_19 AC 22 ms
12,280 KB
testcase_20 AC 21 ms
12,208 KB
testcase_21 AC 21 ms
12,232 KB
testcase_22 AC 22 ms
12,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
// Here your code !
$count = trim(fgets(STDIN));
$weights = explode(' ', trim(fgets(STDIN)));
$sum = array_sum($weights);
if ($sum % 2 == 1) {
    echo 'impossible';
    exit;
}

$point = array_fill(0, $sum + 1, false);
$point[0] = true;

foreach ($weights as $weight) {
    for ($i = $sum; $i >= 0; $i--) {
        if ($point[$i]) {
            $point[$i + $weight] = true;
        }
    }
}
echo ($point[$sum / 2]) ? 'possible' : 'impossible';
0