結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー kagemeka
提出日時 2021-07-30 21:26:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 56,112 KB
最終ジャッジ日時 2024-09-15 22:56:26
合計ジャッジ時間 12,120 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 3 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import typing 
from math import factorial
import numpy as np
import sys


class ModFactorial:
  def __call__(
    self, 
    n: int = 1 << 20,
  ) -> np.array:
    a = np.arange(n); a[0] = 1
    return self.cumprod(a)


  def cumprod(
    self, 
    a: np.array,
  ) -> np.array:
    m = self.__mod
    l = len(a)
    n = int(np.sqrt(l) + 1)
    a = np.resize(a, (n, n))
    for i in range(n-1):
      a[:, i + 1] *= a[:, i]
      a[:, i + 1] %= m
    for i in range(n-1):
      a[i + 1] *= a[i, -1]
      a[i + 1] %= m
    return np.ravel(a)[:l]


  def __init__(
    self,
    modulo: int,
  ) -> typing.NoReturn:
    self.__mod = modulo 
  

  def inv(
    self, 
    n: int = 1 << 20,
  ) -> np.array:
    a = np.arange(1, n + 1)
    m = self.__mod
    x = int(self(n)[-1])
    a[-1] = pow(x, m - 2, m)
    return self.cumprod(
      a[::-1],
    )[n::-1]



def main() -> typing.NoReturn:
  mod = 10 ** 9 + 7

  fn = ModFactorial(mod)
  fact = fn(1 << 18)
  ifact = fn.inv(1 << 18)

  n = int(input())
  c = np.array(
    sys.stdin.readline()
    .split(),
    dtype=np.int64,
  )
  m = fact[n]
  for x in c:
    m *= ifact[x]
    m %= mod
  
  a = m * ifact[n] % mod * c
  a %= mod
  a *= fact[n - 1]
  a %= mod
  d = 1
  sd = 0
  for i in range(n):
    sd += d
    d *= 10
    d %= mod
  s = sd * a % mod
  s *= np.arange(9) + 1
  s %= mod
  print(s.sum() % mod)


main()

  
0