結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 28 ms
10,696 KB
testcase_38 AC 27 ms
11,524 KB
testcase_39 AC 28 ms
10,700 KB
testcase_40 AC 28 ms
10,484 KB
testcase_41 AC 28 ms
10,252 KB
testcase_42 AC 27 ms
10,244 KB
testcase_43 AC 26 ms
10,496 KB
testcase_44 AC 27 ms
10,744 KB
testcase_45 AC 27 ms
10,792 KB
testcase_46 AC 25 ms
10,164 KB
testcase_47 AC 13 ms
6,760 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 39 ms
13,780 KB
testcase_52 AC 40 ms
13,516 KB
testcase_53 AC 39 ms
13,524 KB
testcase_54 AC 39 ms
13,620 KB
testcase_55 AC 40 ms
13,800 KB
testcase_56 AC 40 ms
14,832 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;

    S[] L;
    L ~= S(0, 0, 0);
    foreach (i; 0 .. H) {
        S[] nxt;
        foreach (l; L) {
            foreach (j; -1 .. 2) {
                auto s = l;
                s.num += A[i] * j;
                if (j == -1) s.neg = 1;
                if (j == 1) s.pos = 1;

                nxt ~= s;
            }
        }

        L = nxt;
    }

    S[] R;
    R ~= S(0, 0, 0);
    foreach (i; H .. N) {
        S[] nxt;
        foreach (r; R) {
            foreach (j; -1 .. 2) {
                auto s = r;
                s.num += A[i] * j;
                if (j == -1) s.neg = 1;
                if (j == 1) s.pos = 1;

                nxt ~= s;
            }
        }

        R = nxt;
    }

    auto X = new long[][][](2, 2);
    foreach (l; L) {
        X[l.pos][l.neg] ~= l.num;
    }

    auto Y = new bool[long][][](2, 2);
    foreach (r; R) {
        Y[r.pos][r.neg][r.num] = true;
    }

    bool isOK;

    foreach (x; X[0][1]) {
        long p = x + K;
        if (p in Y[0][1]) isOK = true;
        if (p in Y[1][1]) isOK = true;
    }

    foreach (x; X[1][0]) {
        long n = x - K;
        if (n in Y[1][0]) isOK = true;
        if (n in Y[1][1]) isOK = true;
    }

    foreach (x; X[1][1]) {
        long p = x + K, n = x - K;

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

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