結果
| 問題 |
No.213 素数サイコロと合成数サイコロ (3-Easy)
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-24 23:18:06 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,464 bytes |
| コンパイル時間 | 372 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 32,096 KB |
| 最終ジャッジ日時 | 2025-01-01 18:54:40 |
| 合計ジャッジ時間 | 4,569 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 1 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
import numpy as np
MOD = 10 ** 9 + 7
N, P, C = map(int, read().split())
D1 = (2, 3, 5, 7, 11, 13)
D2 = (4, 6, 8, 9, 10, 12)
fP = np.zeros(13 * P + 1, np.int64)
fC = np.zeros(12 * C + 1, np.int64)
for S in itertools.combinations_with_replacement(D1, P):
fP[sum(S)] += 1
for S in itertools.combinations_with_replacement(D2, C):
fC[sum(S)] += 1
f = np.convolve(fP, fC)
den = -f
den[0] += 1
def coef_of_generating_function(P, Q, N):
"""compute the coefficient [x^N] P/Q of rational power series.
Parameters
----------
P : np.ndarray
numerator.
Q : np.ndarray
denominator
Q[0] == 1 and len(Q) == len(P) + 1 is assumed.
N : int
The coefficient to compute.
"""
def convolve(f, g):
return np.convolve(f, g) % MOD
while N:
Q1 = Q.copy()
Q1[1::2] = np.negative(Q1[1::2])
if N & 1:
P = convolve(P, Q1)[1::2]
else:
P = convolve(P, Q1)[::2]
Q = convolve(Q, Q1)[::2]
N >>= 1
return P[0]
num = np.zeros(len(f) - 1, np.int64)
num[0] = 1
D = len(f) - 1
coefs = [coef_of_generating_function(num, den, n) for n in range(N, N - D - 1, -1) if n >= 0]
answer = 0
for i, x in enumerate(f):
answer += sum(coefs[1:i + 1]) % MOD * x % MOD
print(answer % MOD)
maspy