結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー kokatsukokatsu
提出日時 2022-11-24 07:54:52
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 2,738 ms
コンパイル使用メモリ 204,676 KB
実行使用メモリ 13,100 KB
最終ジャッジ日時 2023-09-04 19:03:33
合計ジャッジ時間 4,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 7 ms
4,376 KB
testcase_39 AC 7 ms
4,380 KB
testcase_40 AC 7 ms
4,380 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 7 ms
4,376 KB
testcase_43 AC 6 ms
4,376 KB
testcase_44 AC 7 ms
4,380 KB
testcase_45 AC 7 ms
4,376 KB
testcase_46 AC 5 ms
4,380 KB
testcase_47 AC 9 ms
5,392 KB
testcase_48 AC 33 ms
12,780 KB
testcase_49 AC 7 ms
4,380 KB
testcase_50 AC 7 ms
4,380 KB
testcase_51 AC 33 ms
12,356 KB
testcase_52 AC 34 ms
12,596 KB
testcase_53 AC 33 ms
12,344 KB
testcase_54 AC 33 ms
13,100 KB
testcase_55 AC 32 ms
11,812 KB
testcase_56 AC 33 ms
12,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long N, K;
    readf("%d %d\n", N, K);

    auto A = readln.chomp.split.to!(long[]);

    long H = N / 2;

    void f(long num, long idx, long lim, ref bool[long][][] list, long pos = 0, long neg = 0) {
        if (idx >= lim) {
            list[pos][neg][num] = true;
        }
        else {
            f(num-A[idx], idx+1, lim, list, pos, 1);
            f(num, idx+1, lim, list, pos, neg);
            f(num+A[idx], idx+1, lim, list, 1, neg);
        }
    }

    auto L = new bool[long][][](2, 2), R = new bool[long][][](2, 2);
    f(0, 0, H, L), f(0, H, N, R);

    bool isOK = A.canFind(K);

    if (K in R[1][1]) isOK = true;

    foreach (key; L[0][1].byKey) {
        long num = K - key;
        if (num in R[1][0]) isOK = true;
        if (num in R[1][1]) isOK = true;
    }

    foreach (key; L[1][0].byKey) {
        long num = K - key;
        if (num in R[0][1]) isOK = true;
        if (num in R[1][1]) isOK = true;
    }

    foreach (key; L[1][1].byKey) {
        long num = K - key;

        foreach (i; 0 .. 2) {
            foreach (j; 0 .. 2) {
                if (num in R[i][j]) isOK = true;
            }
        }
    }

    writeln(isOK ? "Yes" : "No");
}
0