結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー kokatsukokatsu
提出日時 2022-11-24 02:56:15
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,281 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 204,172 KB
実行使用メモリ 12,552 KB
最終ジャッジ日時 2023-09-04 19:03:07
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 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 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 7 ms
5,040 KB
testcase_38 AC 7 ms
4,376 KB
testcase_39 AC 7 ms
5,032 KB
testcase_40 AC 7 ms
4,376 KB
testcase_41 AC 7 ms
4,376 KB
testcase_42 AC 7 ms
4,380 KB
testcase_43 AC 6 ms
4,380 KB
testcase_44 AC 7 ms
4,376 KB
testcase_45 AC 7 ms
4,380 KB
testcase_46 WA -
testcase_47 AC 11 ms
5,360 KB
testcase_48 WA -
testcase_49 AC 7 ms
4,384 KB
testcase_50 WA -
testcase_51 AC 43 ms
10,616 KB
testcase_52 AC 42 ms
10,604 KB
testcase_53 AC 41 ms
10,640 KB
testcase_54 AC 41 ms
10,616 KB
testcase_55 AC 42 ms
10,676 KB
testcase_56 AC 42 ms
10,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct S {
    long num, pos, neg;
}

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;

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

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

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

    foreach (key; L[1][1].byKey) {
        long p = key + K, n = key - K;

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

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