結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 WA -
testcase_37 AC 25 ms
11,016 KB
testcase_38 AC 23 ms
10,224 KB
testcase_39 AC 23 ms
11,724 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 23 ms
10,168 KB
testcase_43 AC 23 ms
10,752 KB
testcase_44 AC 25 ms
10,756 KB
testcase_45 AC 24 ms
10,436 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 24 ms
10,524 KB
testcase_50 WA -
testcase_51 AC 33 ms
14,588 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 31 ms
13,596 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]) {
                if (x in Y[p2][n2]) isOK = true;
            }
        }
    }

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