結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
PHP Deprecated:  Optional parameter $nums declared before required parameter $rest is implicitly treated as a required parameter in Main.php on line 14

Deprecated: Optional parameter $nums declared before required parameter $rest is implicitly treated as a required parameter in Main.php on line 14
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;
    sort($nums);
    echo getCombination($halfSum, $nums, $halfSum, 0)?"possible":"impossible";
} else {
    echo "impossible";
}
echo PHP_EOL;

function getCombination($target, $nums = [], $full, $rest) {
    // if(count($nums) > 0) {
    //     echo "$target"."  "."{$nums[0]}".PHP_EOL;
    //     flush();
    // }
    if($full < $rest) {
        return false;
    }
    if(array_sum($nums) < $target) {
        return false;
    }
    if(count($nums) == 0) {
        return false;
    } else if($nums[0] == $target) {
        return true;
    } else if($target < $nums[0]) {
        return false;
    } else {
        if(getCombination($target-$nums[0], array_slice($nums,1), $full, $rest)) {
            return true;
        }
    }
    $rest += $nums[0];
    return getCombination($target, array_slice($nums, 1), $full, $rest);
}
0