結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-29 13:24:10 |
| 言語 | PHP (843.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 976 bytes |
| コンパイル時間 | 173 ms |
| コンパイル使用メモリ | 32,276 KB |
| 実行使用メモリ | 39,344 KB |
| 最終ジャッジ日時 | 2024-11-06 18:21:05 |
| 合計ジャッジ時間 | 7,649 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 18 TLE * 1 -- * 4 |
コンパイルメッセージ
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
ソースコード
<?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);
}