結果
| 問題 |
No.1629 Sorting Integers (SUM of M)
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-06-21 22:00:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 1,521 bytes |
| コンパイル時間 | 1,951 ms |
| コンパイル使用メモリ | 196,424 KB |
| 最終ジャッジ日時 | 2025-02-14 23:54:50 |
|
ジャッジサーバーID (参考情報) |
judge7 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll modc=1e9+7, MAX=1000000;
vector<ll> f, finv;
ll mod_exp(ll b, ll e, ll m){
if (e > 0 && b == 0) return 0;
ll ans = 1;
b %= m;
while (e > 0){
if ((e & 1LL)) ans = (ans * b) % m;
e = e >> 1LL;
b = (b*b) % m;
}
return ans;
}
ll inv(ll x){
ll ans = 1, e = modc-2;
x %= modc;
while (e > 0){
if ((e & 1LL)) ans = (ans * x) % modc;
e = e >> 1LL;
x = (x*x) % modc;
}
return ans;
}
void init(){
f.resize(MAX+1); finv.resize(MAX+1);
f[0] = 1;
for (int i=1; i<=MAX; i++) f[i] = (f[i-1]*i) % modc;
finv[MAX] = inv(f[MAX]);
for (int i=MAX-1; i>=0; i--) finv[i] = (finv[i+1] * (i+1)) % modc;
}
ll P(ll n, ll k){
if (n < k || k < 0) return 0;
return (f[n] * finv[n-k]) % modc;
}
int main(){
init();
ll N, ans=0, cnt;
cin >> N;
vector<ll> c(10);
for (int i=1; i<=9; i++) cin >> c[i];
for (int i=1; i<=9; i++){
if (c[i] == 0) continue;
cnt = P(N-1, N-1);
for (int j=1; j<=9; j++){
if (i == j){
cnt *= inv(P(c[j]-1, c[j]-1));
cnt %= modc;
}
else{
cnt *= inv(P(c[j], c[j]));
cnt %= modc;
}
}
ans += (cnt*i) % modc;
ans %= modc;
}
cnt = (mod_exp(10, N, modc) - 1) * inv(9) % modc;
cout << (cnt * ans) % modc << endl;
return 0;
}
srjywrdnprkt