結果
| 問題 |
No.1025 Modular Equation
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:02:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,302 bytes |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 82,100 KB |
| 実行使用メモリ | 441,288 KB |
| 最終ジャッジ日時 | 2025-06-12 14:02:54 |
| 合計ジャッジ時間 | 10,974 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 -- * 25 |
ソースコード
import sys
import math
MOD = 10**9 + 7
def main():
p, n, k, b = map(int, sys.stdin.readline().split())
a_list = list(map(int, sys.stdin.readline().split()))
# Precompute x^k mod p for all x in 0..p-1
freq = [0] * p
for x in range(p):
y = pow(x, k, p)
freq[y] += 1
# Precompute inverse for all possible a_i (non-zero)
inv = [1] * p
for a in range(1, p):
inv[a] = pow(a, p-2, p)
# Compute contribution counts for each term
cnt_list = []
for a in a_list:
if a == 0:
cnt = [0] * p
cnt[0] = p
cnt_list.append(cnt)
continue
inv_a = inv[a]
cnt = [0] * p
for r in range(p):
y = (r * inv_a) % p
cnt[r] = freq[y]
cnt_list.append(cnt)
# Initialize DP
dp = [0] * p
dp[0] = 1
# Convolve each term's contribution using FFT-based convolution
for cnt in cnt_list:
new_dp = [0] * p
for r in range(p):
if dp[r] == 0:
continue
for s in range(p):
new_r = (r + s) % p
new_dp[new_r] = (new_dp[new_r] + dp[r] * cnt[s]) % MOD
dp = new_dp
print(dp[b] % MOD)
if __name__ == '__main__':
main()
gew1fw