結果

問題 No.2442 線形写像
ユーザー InTheBloomInTheBloom
提出日時 2023-08-25 21:35:14
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,622 bytes
コンパイル時間 5,239 ms
コンパイル使用メモリ 202,180 KB
実行使用メモリ 4,972 KB
最終ジャッジ日時 2023-08-25 21:35:24
合計ジャッジ時間 6,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,564 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 16 ms
4,972 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N = readln.chomp.to!int;
    long[] A = new long[](2^^N);
    foreach (i; 0..2^^N) {
        A[i] = readln.chomp.to!long;
    }

    // Nが十分に小さいので、全部見ればよい
    // せっかくなので、enumCombを使ってみよう

    foreach (e; enumComb(2^^N, 2)) {
        if ( A[(e[0]^e[1])] != (A[e[0]]^A[e[1]]) ) {
            writeln("No");
            return;
        }
    }

    writeln("Yes");
}

struct enumComb {
    import std.exception;
    import std.format;
    long N, K;
    long[] idx;
    bool isEmpty;

    this (long N, long K) {
        auto msgN = format("Line : %s, N must be greater than or equal to 0. your input = %s", __LINE__, N);
        auto msgK = format("Line : %s, K must be greater than or equal to 0. your input = %s", __LINE__, K);
        enforce(0 <= N, msgN);
        enforce(0 <= K, msgK);

        this.N = N, this.K = K;
        idx = new long[](K);

        // init
        foreach (i; 0..K) {
            idx[i] = i;
        }
        if (N < K) {
            isEmpty = true;
        }
    }

    bool empty() const {
        return isEmpty;
    }

    long[] front() {
        return idx;
    }
    void popFront() {
        long index;
        (){
            foreach (i; 0..K) {
                if (idx[$-i-1] < N-i-1) {
                    idx[$-i-1]++;
                    index = K-i-1;
                    return;
                }
            }
            // there is no choice :(
            isEmpty = true;
        }();

        foreach (i; index+1..K) {
            idx[i] = idx[i-1] + 1;
        }
    }
}
0