結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー yulianess27__yulianess27__
提出日時 2021-06-17 18:27:22
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,953 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 18,576 KB
実行使用メモリ 19,008 KB
最終ジャッジ日時 2023-09-01 03:33:03
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 15 ms
18,836 KB
testcase_03 AC 15 ms
18,728 KB
testcase_04 AC 15 ms
18,764 KB
testcase_05 AC 15 ms
18,736 KB
testcase_06 AC 15 ms
18,772 KB
testcase_07 AC 16 ms
18,608 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 15 ms
18,608 KB
testcase_16 WA -
testcase_17 AC 16 ms
18,732 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 16 ms
18,740 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 15 ms
18,656 KB
testcase_38 AC 15 ms
18,772 KB
testcase_39 AC 15 ms
18,756 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 15 ms
18,760 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 16 ms
18,784 KB
testcase_46 AC 16 ms
18,816 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 15 ms
18,772 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 16 ms
18,736 KB
testcase_55 WA -
testcase_56 AC 15 ms
18,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
// 黒板に N 個の整数  が書かれています.引き算が得意なゅゅちゃんは 0 以上 N-1 以下の任意の回数,以下の操作を繰り返すことができます.
// 黒板に書かれている数を 2 つ選んで消す.消した数を  として, と x-y, y-x のどちらか一方を黒板に書く.
// この操作によって,黒板に書かれている数に K が含まれている状態にすることができるか判定してください.
list($n, $k) = explode(" ", trim(fgets(STDIN)));
$list = explode(" ", trim(fgets(STDIN)));
if (in_array($k, $list)) echo 'Yes';

$res = false;
// 順列
function permutations(array $elements) {
    global $n, $k, $res;
    if ($exit) return;
    if (count($elements) <= 1) {
        yield $elements;
    } else {
        foreach (permutations(array_slice($elements, 1)) as $permutation) {
            foreach (range(0, count($elements) - 1) as $i) {
                $p = array_merge( array_slice($permutation, 0, $i), [$elements[0]], array_slice($permutation, $i) );
                if (count($p) < $n) {
                    yield $p;
                } else {
                    $r = [];
                    foreach($p as $v) {
                        if (empty($r)) {
                            $r = [$v, -$v];
                        } else {
                            $t = [];
                            foreach($r as $rr) {
                                $t[] = $rr + $v; 
                                $t[] = $rr - $v;
                            }
                            $r = array_unique($t);
                            if (in_array($k, $r)) {
                                $res = true;
                                return;
                            }
                            unset($t);
                        }
                    }
                }
            }
        }
    }
}
permutations($list);
echo $res?"Yes":"No";
0