結果

問題 No.4 おもりと天秤
ユーザー papinianuspapinianus
提出日時 2016-07-29 13:05:17
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 638 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 31,252 KB
実行使用メモリ 38,452 KB
最終ジャッジ日時 2024-04-24 10:42:29
合計ジャッジ時間 7,708 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
31,268 KB
testcase_01 AC 34 ms
30,924 KB
testcase_02 AC 39 ms
30,904 KB
testcase_03 AC 38 ms
31,332 KB
testcase_04 AC 38 ms
31,208 KB
testcase_05 AC 39 ms
31,268 KB
testcase_06 AC 39 ms
31,120 KB
testcase_07 AC 39 ms
31,304 KB
testcase_08 AC 37 ms
31,004 KB
testcase_09 AC 38 ms
31,112 KB
testcase_10 AC 35 ms
31,020 KB
testcase_11 AC 36 ms
31,304 KB
testcase_12 AC 34 ms
30,964 KB
testcase_13 AC 35 ms
31,272 KB
testcase_14 AC 34 ms
31,168 KB
testcase_15 AC 35 ms
31,032 KB
testcase_16 AC 35 ms
31,008 KB
testcase_17 AC 35 ms
31,168 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$num = trim(fgets(STDIN));
$nums = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($nums);
if($sum%2 == 0) {
    $halfSum = $sum/2;
    rsort($nums);
    echo getCombination($halfSum, $nums)?"possible":"impossible";
} else {
    echo "impossible";
}
echo PHP_EOL;

function getCombination($target, $nums = []) {
    if(count($nums) == 0) {
        return false;
    } else if($nums[0] == $target) {
        return true;
    }
    if($target > $nums[0]) {
        if(getCombination($target-$nums[0], array_slice($nums,1))) {
            return true;
        }
    }
        return getCombination($target, array_slice($nums, 1));
}
0