結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,388 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 28 ms
10,504 KB
testcase_38 AC 27 ms
10,256 KB
testcase_39 AC 27 ms
10,744 KB
testcase_40 AC 28 ms
10,448 KB
testcase_41 AC 28 ms
10,728 KB
testcase_42 AC 27 ms
10,228 KB
testcase_43 AC 27 ms
10,696 KB
testcase_44 AC 27 ms
10,704 KB
testcase_45 AC 27 ms
10,768 KB
testcase_46 WA -
testcase_47 AC 13 ms
6,564 KB
testcase_48 AC 39 ms
13,464 KB
testcase_49 AC 26 ms
11,716 KB
testcase_50 WA -
testcase_51 AC 39 ms
14,232 KB
testcase_52 AC 38 ms
13,796 KB
testcase_53 AC 39 ms
13,608 KB
testcase_54 AC 38 ms
14,572 KB
testcase_55 AC 39 ms
13,780 KB
testcase_56 AC 39 ms
13,780 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 (i; 0 .. 4) {
        long p1 = (i >> 1) & 1, n1 = i & 1;

        foreach (j; 0 .. 4) {
            long p2 = (j >> 1) & 1, n2 = j & 1;

            if (p1 == 0 && p2 == 0) continue;
            if (n1 == 0 && n2 == 0) continue;

            foreach (x; X[p1][n1]) {
                long p = x + K, n = x - K;
                if (p in Y[p2][n2]) isOK = true;
                if (n in Y[p2][n2]) isOK = true;
            }
        }
    }

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