結果
| 問題 |
No.1629 Sorting Integers (SUM of M)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-10 19:49:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 2,336 bytes |
| コンパイル時間 | 1,996 ms |
| コンパイル使用メモリ | 198,360 KB |
| 最終ジャッジ日時 | 2025-02-08 01:17:24 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
long long fac[N+1],inv[N+1],invf[N+1];
fac[0]=inv[0]=invf[0]=1;
fac[1]=inv[1]=invf[1]=1;
for(int i=2;i<=N;i++){
fac[i]=fac[i-1]*i%mod;
inv[i]=inv[mod%i]*(mod-mod/i)%mod;
invf[i]=invf[i-1]*inv[i]%mod;
}
array<int,10>cnt;
for(int i=1;i<10;i++)cin>>cnt[i];
long long t=1,ans=0;
for(int i=0;i<N;i++){
if(cnt[1])ans=(ans+fac[N-1]*invf[cnt[1]-1]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t)%mod;
if(cnt[2])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]-1]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t%mod*2)%mod;
if(cnt[3])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]-1]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t%mod*3)%mod;
if(cnt[4])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]-1]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t%mod*4)%mod;
if(cnt[5])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]-1]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t%mod*5)%mod;
if(cnt[6])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]-1]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t%mod*6)%mod;
if(cnt[7])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]-1]%mod*invf[cnt[8]]%mod*invf[cnt[9]]%mod*t%mod*7)%mod;
if(cnt[8])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]-1]%mod*invf[cnt[9]]%mod*t%mod*8)%mod;
if(cnt[9])ans=(ans+fac[N-1]*invf[cnt[1]]%mod*invf[cnt[2]]%mod*invf[cnt[3]]%mod*invf[cnt[4]]%mod*invf[cnt[5]]%mod*invf[cnt[6]]%mod*invf[cnt[7]]%mod*invf[cnt[8]]%mod*invf[cnt[9]-1]%mod*t%mod*9)%mod;
t=t*10%mod;
}
cout<<ans<<'\n';
}