結果
| 問題 |
No.243 出席番号(2)
|
| ユーザー |
maspy
|
| 提出日時 | 2020-03-27 09:25:17 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 803 ms / 2,000 ms |
| コード長 | 1,166 bytes |
| コンパイル時間 | 181 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 32,240 KB |
| 最終ジャッジ日時 | 2025-01-02 08:20:12 |
| 合計ジャッジ時間 | 21,014 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7
def cumprod(A, MOD=MOD):
L = len(A)
Lsq = int(L**.5 + 1)
A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
A[:, n] *= A[:, n - 1]
A[:, n] %= MOD
for n in range(1, Lsq):
A[n] *= A[n - 1, -1]
A[n] %= MOD
return A.ravel()[:L]
def make_fact(U, MOD=MOD):
x = np.arange(U, dtype=np.int64)
x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64)
x[0] = pow(int(fact[-1]), MOD - 2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
fact.flags.writeable = False
fact_inv.flags.writeable = False
return fact, fact_inv
N, *A = map(int, read().split())
counter = [0] * 5000
for x in A:
counter[x] += 1
# 選ぶ人数 -> まともな包除ルールの選び方
dp = np.zeros(N + 1, np.int64)
dp[0] = 1
for x in counter[:N]:
dp[1:] += dp[:-1] * x
dp %= MOD
fact, fact_inv = make_fact(N + 1)
dp *= fact[::-1]
dp[1::2] *= (-1)
answer = (dp % MOD).sum() % MOD
print(answer)
maspy