結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,820 KB
testcase_01 AC 16 ms
18,852 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 15 ms
18,804 KB
testcase_09 AC 15 ms
18,836 KB
testcase_10 AC 15 ms
18,844 KB
testcase_11 WA -
testcase_12 AC 15 ms
18,924 KB
testcase_13 AC 15 ms
18,872 KB
testcase_14 AC 15 ms
18,872 KB
testcase_15 WA -
testcase_16 AC 16 ms
18,872 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 14 ms
18,784 KB
testcase_22 AC 14 ms
18,836 KB
testcase_23 AC 15 ms
18,868 KB
testcase_24 AC 14 ms
18,828 KB
testcase_25 WA -
testcase_26 AC 14 ms
18,864 KB
testcase_27 AC 15 ms
18,628 KB
testcase_28 AC 14 ms
18,764 KB
testcase_29 AC 15 ms
18,868 KB
testcase_30 AC 15 ms
18,872 KB
testcase_31 AC 15 ms
18,912 KB
testcase_32 AC 15 ms
18,932 KB
testcase_33 WA -
testcase_34 AC 15 ms
18,856 KB
testcase_35 AC 15 ms
18,824 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 15 ms
18,908 KB
testcase_41 AC 14 ms
18,832 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 14 ms
18,832 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 15 ms
18,796 KB
testcase_48 AC 15 ms
18,764 KB
testcase_49 AC 15 ms
18,784 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 15 ms
18,808 KB
testcase_53 AC 15 ms
18,796 KB
testcase_54 WA -
testcase_55 AC 15 ms
18,928 KB
testcase_56 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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';

// 順列
function permutations(array $elements) {
    global $n, $k;
    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;
                            }
                            if (in_array($k, $r)) {
                                return true;
                            }
                            $r = array_unique($t);
                        }
                    }
                }
            }
        }
    }
}

$ret = permutations($list);
echo $ret?"Yes":"No";
0