結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー monnumonnu
提出日時 2021-07-30 20:52:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 3,639 ms
コンパイル使用メモリ 227,476 KB
実行使用メモリ 9,356 KB
最終ジャッジ日時 2023-10-14 03:08:07
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 6 ms
5,716 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 13 ms
6,668 KB
testcase_08 AC 9 ms
5,740 KB
testcase_09 AC 12 ms
6,268 KB
testcase_10 AC 9 ms
5,972 KB
testcase_11 AC 7 ms
4,948 KB
testcase_12 AC 16 ms
5,932 KB
testcase_13 AC 17 ms
6,308 KB
testcase_14 AC 12 ms
5,136 KB
testcase_15 AC 17 ms
6,576 KB
testcase_16 AC 17 ms
6,192 KB
testcase_17 AC 31 ms
9,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 100000
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<ll> c(9);
  for(int i=0;i<9;i++){
    cin>>c[i];
  }
  vector<ll> res(N,1);
  for(int i=1;i<N;i++){
    res[i]=10*res[i-1]%MOD;
  }
  vector<ll> fac(N+1,1);
  vector<ll> inv(N+1,1);
  vector<ll> finv(N+1,1);
  for(int i=2;i<=N;i++){
    fac[i]=(ll)i*fac[i-1]%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }

  ll ans=0;
  ll x=fac[N-1];
  for(int i=0;i<9;i++){
    x*=finv[c[i]];
    x%=MOD;
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<9;j++){
      if(c[j]==0){
        continue;
      }
      ll y=(x*fac[c[j]]%MOD)*finv[c[j]-1]%MOD;
      y=res[i]*y%MOD;
      y*=(ll)j+1;
      y%=MOD;
      ans+=y;
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
}
0