結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー 👑 ygussanyygussany
提出日時 2021-07-30 20:38:56
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 29,968 KB
実行使用メモリ 4,904 KB
最終ジャッジ日時 2023-10-14 02:52:45
合計ジャッジ時間 1,586 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

const int Mod = 1000000007;
long long fact[200001], fact_inv[200001];

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(int n, int k)
{
	return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod;
}

int main()
{
	int i, j, N, c[10];
	scanf("%d", &N);
	for (i = 1; i <= 9; i++) scanf("%d", &(c[i]));
	for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	
	int k;
	long long ans = 0, tmp = 1, comb[10];
	for (i = 1; i <= 9; i++) {
		if (c[i] == 0) comb[i] = 0;
		else {
			for (j = 1, k = N - 1, comb[i] = 1; j <= 9; j++) {
				if (j == i) {
					comb[i] = comb[i] * combination(k, c[j] - 1) % Mod;
					k -= c[j] - 1;					
				} else {
					comb[i] = comb[i] * combination(k, c[j]) % Mod;
					k -= c[j];
				}
			}
		}
	}
	for (i = 1; i <= N; i++, tmp = tmp * 10 % Mod) {
		for (j = 1; j <= 9; j++) ans += tmp * j * comb[j] % Mod;
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0