結果
| 問題 |
No.2709 1975 Powers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 14:02:18 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,571 bytes |
| コンパイル時間 | 4,317 ms |
| コンパイル使用メモリ | 178,304 KB |
| 実行使用メモリ | 10,368 KB |
| 最終ジャッジ日時 | 2024-09-30 18:50:35 |
| 合計ジャッジ時間 | 13,764 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 16 |
ソースコード
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) {
// なんかMLEしたのでnextdpやる
A.sort;
auto dp = new long[][](5, P);
auto ndp = new long[][](5, P);
// dp[i][j][k] := 先頭i個からj個とってあまりがk
dp[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) {
ndp[j + 1][(k + memo[j][i]) % P] += dp[j][k];
}
// 取らない
ndp[j][k] += dp[j][k];
}
}
swap(dp, ndp);
}
writeln(dp[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;
}