結果
問題 | No.1629 Sorting Integers (SUM of M) |
ユーザー |
![]() |
提出日時 | 2021-07-30 20:33:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 2,898 ms |
コンパイル使用メモリ | 171,728 KB |
実行使用メモリ | 6,356 KB |
最終ジャッジ日時 | 2024-09-15 22:25:16 |
合計ジャッジ時間 | 2,703 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long modpow(long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } vector<long long> mf = {1}; vector<long long> mfi = {1}; long long modfact(int n){ if (mf.size() > n){ return mf[n]; } else { for (int i = mf.size(); i <= n; i++){ long long next = mf.back() * i % MOD; mf.push_back(next); mfi.push_back(modinv(next)); } return mf[n]; } } long long modfactinv(int n){ if (mfi.size() > n){ return mfi[n]; } else { return modinv(modfact(n)); } } int main(){ int N; cin >> N; vector<int> c(9); for (int i = 0; i < 9; i++){ cin >> c[i]; } long long s = 0; for (int i = 0; i < 9; i++){ s += (i + 1) * c[i]; } s *= modinv(N); s %= MOD; long long s2 = 0; for (int i = 0; i < N; i++){ s2 *= 10; s2++; s2 %= MOD; } long long a = s * s2 % MOD; a *= modfact(N); a %= MOD; for (int i = 0; i < 9; i++){ a *= modfactinv(c[i]); a %= MOD; } cout << a << endl; }