結果

問題 No.2709 1975 Powers
ユーザー InIn
提出日時 2024-03-31 13:56:27
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,398 bytes
コンパイル時間 3,615 ms
コンパイル使用メモリ 168,804 KB
実行使用メモリ 218,400 KB
最終ジャッジ日時 2024-03-31 13:56:35
合計ジャッジ時間 7,208 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std;

void main () {
    int N, P, Q; readln.read(N, P, Q);
    auto A = readln.split.to!(int[]);

    solve(N, P, Q, A);
}

void solve (int N, int P, int Q, int[] A) {
    A.sort;
    auto dp = new long[][][](N + 1, 5, P);
    // dp[i][j][k] := 先頭i個からj個とってあまりがk

    dp[0][0][0] = 1;

    const x = [10, 9, 7, 5];

    foreach (i; 0..N) {
        foreach (j; 0..5) {
            foreach (k; 0..P) {
                // 取る
                if (j + 1 <= 4) {
                    dp[i + 1][j + 1][(k + mod_pow(x[j], A[i], P)) % P] += dp[i][j][k];
                }

                // 取らない
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }

    writeln(dp[N][4][Q]);
}

void read (T...) (string S, ref T args) {
    import std.conv : to;
    import std.array : split;
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}

long mod_pow (long a, long x, const long MOD)
in {
    assert(0 <= x, "x must satisfy 0 <= x");
    assert(1 <= MOD, "MOD must satisfy 1 <= MOD");
    assert(MOD <= int.max, "MOD must satisfy MOD*MOD <= long.max");
}
do {
    // normalize
    a %= MOD; a += MOD; a %= MOD;

    long res = 1L;
    long base = a;
    while (0 < x) {
        if (0 < (x&1)) (res *= base) %= MOD;
        (base *= base) %= MOD;
        x >>= 1;
    }

    return res % MOD;
}
0