結果
問題 |
No.243 出席番号(2)
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:35:42 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 888 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 81,760 KB |
実行使用メモリ | 76,900 KB |
最終ジャッジ日時 | 2025-04-15 23:36:44 |
合計ジャッジ時間 | 3,401 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 MLE * 25 |
ソースコード
MOD = 10**9 + 7 N = int(input()) A = [int(input()) for _ in range(N)] from collections import defaultdict # Count the occurrences of each disliked number cnt = defaultdict(int) for a in A: cnt[a] += 1 # DP to compute C_k: number of ways to choose k elements with all distinct A_i dp = [0] * (N + 1) dp[0] = 1 for v in cnt: c = cnt[v] # Iterate backwards to avoid overwriting the values we need to use for j in range(N, -1, -1): if dp[j]: if j + 1 <= N: dp[j + 1] = (dp[j + 1] + dp[j] * c) % MOD # Precompute factorials modulo MOD fact = [1] * (N + 1) for i in range(1, N + 1): fact[i] = fact[i - 1] * i % MOD # Calculate the answer using inclusion-exclusion principle ans = 0 for k in range(0, N + 1): term = pow(-1, k, MOD) * dp[k] % MOD term = term * fact[N - k] % MOD ans = (ans + term) % MOD print(ans % MOD)