結果
問題 | No.1629 Sorting Integers (SUM of M) |
ユーザー | Theta |
提出日時 | 2024-04-16 19:01:28 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,797 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 67,264 KB |
最終ジャッジ日時 | 2024-10-07 19:47:39 |
合計ジャッジ時間 | 2,136 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
ソースコード
from functools import cache from atcoder.modint import ModContext, Modint from collections import Counter from math import factorial import sys from bisect import bisect_right from itertools import count, accumulate sys.setrecursionlimit(300000) def COMinit(upper: int, mod_: int) -> tuple[list[int], list[int], list[int]]: fac = [0 for _ in range(upper)] finv = [0 for _ in range(upper)] inv = [0 for _ in range(upper)] fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, upper): fac[i] = (fac[i - 1] * i) % mod_ inv[i] = (mod_ - inv[mod_ % i] * (mod_ // i)) % mod_ finv[i] = (finv[i - 1] * inv[i]) % mod_ return fac, finv, inv def main(): N = int(input()) ctr = list(map(int, input().split())) MOD = int(1e9 + 7) fac, finv, inv = COMinit(N + 20, MOD) @cache def com(n: int, k: int) -> int: if n < k: return 0 if (n < 0 or k < 0): return 0 return (fac[n] * finv[k] * finv[n - k]) % MOD seq_1 = 0 for _ in range(N): seq_1 *= 10 seq_1 += 1 seq_1 %= MOD M_sum = 0 for num, ctr_elm in enumerate(ctr, 1): if ctr_elm == 0: continue tmp_patterns = 1 rest = N - 1 for tmp_num, tmp_ctr_elm in enumerate(ctr, 1): if num == tmp_num: tmp_patterns *= com(rest, tmp_ctr_elm - 1) rest -= tmp_ctr_elm - 1 else: tmp_patterns *= com(rest, tmp_ctr_elm) rest -= tmp_ctr_elm M_sum += tmp_patterns * seq_1 * num M_sum %= MOD print(M_sum) if __name__ == "__main__": main()