結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー inksamuraiinksamurai
提出日時 2021-07-30 20:44:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,702 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 105,868 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2023-10-14 03:02:23
合計ジャッジ時間 2,046 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,480 KB
testcase_01 AC 7 ms
6,476 KB
testcase_02 AC 7 ms
6,464 KB
testcase_03 AC 6 ms
6,500 KB
testcase_04 AC 8 ms
6,796 KB
testcase_05 AC 7 ms
6,472 KB
testcase_06 AC 7 ms
6,540 KB
testcase_07 AC 9 ms
7,060 KB
testcase_08 AC 8 ms
6,796 KB
testcase_09 AC 9 ms
7,060 KB
testcase_10 AC 9 ms
7,208 KB
testcase_11 AC 8 ms
6,672 KB
testcase_12 AC 11 ms
7,068 KB
testcase_13 AC 11 ms
7,144 KB
testcase_14 AC 10 ms
6,660 KB
testcase_15 AC 11 ms
7,056 KB
testcase_16 AC 11 ms
7,048 KB
testcase_17 AC 16 ms
7,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define _376o25z ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;

const int mxn=400000;
const int mod=1000000007;

//snuke's modular int
struct modularint{
	ll x;
	modularint(ll x=0):x(x%mod){}
	modularint& operator+=(const modularint a){
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator-=(const modularint a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator*=(const modularint a){
		(x *= a.x) %= mod;
		return *this;
	}
	modularint operator+(const modularint a)const{
		modularint res(*this);
		return res+=a;
	}
	modularint operator-(const modularint a)const{
		modularint res(*this);
		return res-=a;
	}
	modularint operator*(const modularint a)const{
		modularint res(*this);
		return res*=a;
	}
	modularint pow(int n)const{
		modularint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modularint inv()const{
		return pow(mod-2);
	}
};
using mint=modularint;

mint fact[mxn+10];
void prefact(){
fact[0]=fact[1]=1;
  crep(i,2,mxn){
    mint x=i;
    fact[i]=fact[i-1]*x;
  }
}

mint cnk(ll k , ll n){
  if(k>n) return 0;
  mint e=fact[k]*fact[n-k];
  return fact[n] * e.inv();
}

int main(){
_376o25z;
prefact();
	int n;
	cin>>n;
	mint e=fact[n];
	vec(ll) a(12);
	rep(i,9){
		cin>>a[i];
	}
	vec(mint) pot(n+10);
	pot[0]=1;
	crep(i,1,n){
		mint x=10;
		pot[i]=pot[i-1]*x;
	}
	mint ans=0;
	rep(i,9){
		if(a[i]==0) continue;
		mint e=fact[n-1];
		rep(j,9){
			if(i==j){
				if(a[j]-1>0) e=e*fact[a[j]-1].inv();
			}else{
				if(a[j]>0) e=e*fact[a[j]].inv();
			}
		}
		mint ef=i+1;
		mint now=0;
		rep(x,n){
			now=now+pot[x]*e*ef;
		}
		ans+=now;
		// cout<<e.x<<" ";
	}
	cout<<ans.x<<"\n";

// 
	return 0;
}
0