結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー the-xinthe-xin
提出日時 2021-07-30 21:19:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 68,100 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 03:03:44
合計ジャッジ時間 1,499 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 60,mod=1e9+7;
typedef long long LL;
int cnt[N];
LL qpow(LL x,LL k){
	LL res=1;
	while(k){
		if(k&1)res=res*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=9;i++){
		scanf("%d",&cnt[i]);
	}
	LL t=1;
	LL c=1,res=0;
	for(int i=1;i<=n;i++){
		t=t*i%mod;
		res=(res+c)%mod;
		c=c*10%mod;
	}
	LL ans=0;
	for(int i=1;i<=9;i++){
		LL z=1;
		for(int j=1;j<=cnt[i];j++){
			z=z*j%mod;
		}
		t=t*qpow(z,mod-2)%mod;
	}
	for(int i=1;i<=9;i++){
		if(cnt[i]){
			ans=(ans+t*cnt[i]%mod*i%mod*qpow(n,mod-2)%mod*res%mod)%mod;
		}
	}
	cout<<ans;
	return 0;
}
0