結果

問題 No.2709 1975 Powers
ユーザー InIn
提出日時 2024-03-31 13:59:04
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,500 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 168,932 KB
実行使用メモリ 715,668 KB
最終ジャッジ日時 2024-03-31 13:59:27
合計ジャッジ時間 19,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 379 ms
212,668 KB
testcase_03 AC 689 ms
353,288 KB
testcase_04 MLE -
testcase_05 AC 846 ms
481,076 KB
testcase_06 AC 269 ms
152,452 KB
testcase_07 AC 111 ms
65,848 KB
testcase_08 AC 790 ms
448,744 KB
testcase_09 MLE -
testcase_10 AC 118 ms
70,176 KB
testcase_11 AC 179 ms
103,480 KB
testcase_12 AC 656 ms
360,544 KB
testcase_13 MLE -
testcase_14 AC 348 ms
198,172 KB
testcase_15 AC 771 ms
429,032 KB
testcase_16 AC 486 ms
273,812 KB
testcase_17 AC 137 ms
80,068 KB
testcase_18 AC 666 ms
377,396 KB
testcase_19 MLE -
testcase_20 AC 339 ms
195,348 KB
testcase_21 AC 775 ms
446,696 KB
testcase_22 MLE -
testcase_23 MLE -
testcase_24 AC 608 ms
334,016 KB
testcase_25 MLE -
testcase_26 MLE -
権限があれば一括ダウンロードができます

ソースコード

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];

    auto memo = new long[][](4, N);
    foreach (i; 0..4) foreach (j; 0..N) memo[i][j] = mod_pow(x[i], A[j], P);

    foreach (i; 0..N) {
        foreach (j; 0..5) {
            foreach (k; 0..P) {
                // 取る
                if (j + 1 <= 4) {
                    dp[i + 1][j + 1][(k + memo[j][i]) % 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