結果
| 問題 |
No.243 出席番号(2)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:32:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 825 bytes |
| コンパイル時間 | 322 ms |
| コンパイル使用メモリ | 82,476 KB |
| 実行使用メモリ | 75,460 KB |
| 最終ジャッジ日時 | 2025-04-15 23:33:16 |
| 合計ジャッジ時間 | 3,416 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 MLE * 24 |
ソースコード
MOD = 10**9 + 7
N = int(input())
A = [int(input()) for _ in range(N)]
from collections import defaultdict
freq = defaultdict(int)
for a in A:
freq[a] += 1
# Precompute factorials modulo MOD
fact = [1] * (N + 1)
for i in range(1, N + 1):
fact[i] = fact[i-1] * i % MOD
# Initialize DP array
dp = [0] * (N + 2) # Extra space to avoid index issues
dp[0] = 1
current_max_degree = 0
for x in freq:
c = freq[x]
# Iterate from current_max_degree down to 0
for k in range(current_max_degree, -1, -1):
dp[k + 1] = (dp[k + 1] + dp[k] * c) % MOD
current_max_degree += 1
# Calculate the answer
ans = 0
for k in range(0, current_max_degree + 1):
if k > N:
continue
sign = -1 if k % 2 else 1
term = (sign * dp[k] * fact[N - k]) % MOD
ans = (ans + term) % MOD
print(ans % MOD)
lam6er