結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-29 13:05:17 |
| 言語 | PHP (843.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 638 bytes |
| コンパイル時間 | 238 ms |
| コンパイル使用メモリ | 32,148 KB |
| 実行使用メモリ | 38,964 KB |
| 最終ジャッジ日時 | 2024-11-06 18:20:57 |
| 合計ジャッジ時間 | 7,721 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 4 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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));
}