結果
問題 |
No.1025 Modular Equation
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:51:23 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,376 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 81,872 KB |
実行使用メモリ | 848,900 KB |
最終ジャッジ日時 | 2025-04-16 15:52:29 |
合計ジャッジ時間 | 7,180 ms |
ジャッジサーバーID (参考情報) |
judge4 / 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()