結果
問題 | No.1629 Sorting Integers (SUM of M) |
ユーザー | H20 |
提出日時 | 2021-07-30 22:16:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 2,222 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 115,712 KB |
最終ジャッジ日時 | 2024-09-16 00:41:19 |
合計ジャッジ時間 | 2,743 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
# ModInt 参考は以下のサイト # https://qiita.com/wotsushi/items/c936838df992b706084c MOD = 10**9+7 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return ( ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other) ) def __sub__(self, other): return ( ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other) ) def __mul__(self, other): return ( ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other) ) def __truediv__(self, other): return ( ModInt( self.x * pow(other.x, MOD - 2, MOD) ) if isinstance(other, ModInt) else ModInt(self.x * pow(other, MOD - 2, MOD)) ) def __pow__(self, other): return ( ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD)) ) __radd__ = __add__ def __rsub__(self, other): return ( ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x) ) __rmul__ = __mul__ def __rtruediv__(self, other): return ( ModInt( other.x * pow(self.x, MOD - 2, MOD) ) if isinstance(other, ModInt) else ModInt(other * pow(self.x, MOD - 2, MOD)) ) def __rpow__(self, other): return ( ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, MOD)) ) N = int(input()) A = list(map(int, input().split())) L = [1] mod = MOD for i in range(3*10**5): L.append(L[-1]*10%mod) fact = [1] for n in range(1,3*10**5): fact.append(fact[-1]*n%MOD) temp = ModInt(fact[N]) for i in range(9): temp = temp / ModInt(fact[A[i]]) su = ModInt(0) for i in range(9): su = su + (i+1) * temp * ModInt(A[i]) / ModInt(N) ans = 0 for i in range(N): ans = ans + L[i]*su print(ans)