結果
| 問題 |
No.1025 Modular Equation
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:50:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,290 bytes |
| コンパイル時間 | 165 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 89,640 KB |
| 最終ジャッジ日時 | 2025-03-31 17:51:59 |
| 合計ジャッジ時間 | 8,931 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 -- * 25 |
ソースコード
MOD = 10**9 + 7
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
p = int(input[ptr]); ptr += 1
n = int(input[ptr]); ptr += 1
k = int(input[ptr]); ptr += 1
b = int(input[ptr]); ptr += 1
a_list = list(map(int, input[ptr:ptr+n]))
current_dp = [0] * p
current_dp[0] = 1
for a in a_list:
if a == 0:
for j in range(p):
current_dp[j] = (current_dp[j] * p) % MOD
continue
cnt = [0] * p
cnt[(0 * a) % p] += 1 # x=0
if p > 1:
exponent_mod = k % (p-1) if (p-1) != 0 else k # p-1 is 0 only if p=1, which can't be here
for x in range(1, p):
pow_val = pow(x, exponent_mod, p)
c = (a * pow_val) % p
cnt[c] += 1
non_zero = [(c, cnt[c]) for c in range(p) if cnt[c] > 0]
new_dp = [0] * p
for j in range(p):
if current_dp[j] == 0:
continue
val = current_dp[j]
for c, freq in non_zero:
new_j = (j + c) % p
new_dp[new_j] = (new_dp[new_j] + val * freq) % MOD
current_dp = new_dp
print(current_dp[b] % MOD)
if __name__ == "__main__":
main()
lam6er