結果
| 問題 |
No.1025 Modular Equation
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 22:18:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,376 bytes |
| コンパイル時間 | 155 ms |
| コンパイル使用メモリ | 81,708 KB |
| 実行使用メモリ | 848,892 KB |
| 最終ジャッジ日時 | 2025-04-15 22:20:31 |
| 合計ジャッジ時間 | 6,852 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 MLE * 1 -- * 25 |
ソースコード
import sys
import math
from collections import defaultdict
MOD = 10**9 + 7
def main():
p, n, k, b = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
zero_terms = []
non_zero_terms = []
for ai in a:
if ai == 0:
zero_terms.append(ai)
else:
non_zero_terms.append(ai % p)
m = len(zero_terms)
if not non_zero_terms:
if b == 0:
ans = pow(p, n, MOD)
else:
ans = 0
print(ans % MOD)
return
d = math.gcd(k, p-1)
t = (p-1) // d
S = []
for x in range(1, p):
if pow(x, t, p) == 1:
S.append(x)
terms_freq = []
for ai in non_zero_terms:
freq = defaultdict(int)
freq[0] = 1
ai_mod = ai % p
for x in S:
r = (ai_mod * x) % p
freq[r] += d
terms_freq.append(list(freq.items()))
dp = [0] * p
dp[0] = 1
for freq in terms_freq:
new_dp = [0] * p
for s in range(p):
if dp[s] == 0:
continue
for r, cnt in freq:
new_s = (s + r) % p
new_dp[new_s] = (new_dp[new_s] + dp[s] * cnt) % MOD
dp = new_dp
ans = dp[b % p] * pow(p, m, MOD) % MOD
print(ans)
if __name__ == "__main__":
main()
lam6er