結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー kokatsukokatsu
提出日時 2022-11-24 00:34:14
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 206,256 KB
実行使用メモリ 5,576 KB
最終ジャッジ日時 2023-09-04 19:01:50
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 WA -
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 3 ms
4,384 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 WA -
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,384 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 3 ms
4,384 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 3 ms
4,384 KB
testcase_55 WA -
testcase_56 AC 3 ms
4,384 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;

    long[long] L, R;
    L[0] = R[0] = 1;

    long l;
    foreach (i; 0 .. H) {
        long[long] nxt;
        nxt[0] = L[0];
        foreach (key, val; L) {
            foreach (j; [-1, 1]) {
                nxt[key+A[i]*j] += val;
            }
        }

        l += A[i];
        L = nxt;
    }

    foreach (a; [-l, 0, l]) {
        --L[a];
        if (L[a] == 0) L.remove(a);
    }

    long r;
    foreach (i; H .. N) {
        long[long] nxt;
        nxt[0] = R[0];
        foreach (key, val; R) {
            foreach (j; [-1, 1]) {
                nxt[key+A[i]*j] += val;
            }
        }

        r += A[i];
        R = nxt;
    }

    foreach (a; [-r, 0, r]) {
        --R[a];
        if (R[a] == 0) R.remove(a);
    }

    bool isOK;
    foreach (key; L.byKey) {
        if (key + K in R) isOK = true;
        if (key - K in R) isOK = true;
    }

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