結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー 夜
提出日時 2021-07-30 21:04:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 92,664 KB
実行使用メモリ 9,576 KB
最終ジャッジ日時 2023-10-14 01:57:17
合計ジャッジ時間 2,054 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,036 KB
testcase_01 AC 15 ms
8,036 KB
testcase_02 AC 15 ms
8,084 KB
testcase_03 AC 16 ms
8,040 KB
testcase_04 AC 17 ms
8,856 KB
testcase_05 AC 15 ms
8,160 KB
testcase_06 AC 16 ms
8,284 KB
testcase_07 AC 20 ms
8,980 KB
testcase_08 AC 19 ms
8,784 KB
testcase_09 AC 19 ms
8,848 KB
testcase_10 AC 19 ms
8,988 KB
testcase_11 AC 18 ms
8,564 KB
testcase_12 AC 19 ms
8,888 KB
testcase_13 AC 19 ms
8,832 KB
testcase_14 AC 17 ms
8,548 KB
testcase_15 AC 19 ms
8,860 KB
testcase_16 AC 19 ms
9,100 KB
testcase_17 AC 23 ms
9,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 1000000007;
long long m_pow(long long x, long long y) {
	long long ans = 1;
	while (y > 0) {
		if ((y & 1) == 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
long long fac[200020], finv[200020], inv[200020];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long k[200020];
long long c[10];
int main() {
	COMinit();
	long long n;
	cin >> n;
	long long ans = 0;
	long long sum = 0, p = 1;
	for (int i = 1; i <= 9; i++) {
		cin >> c[i];
	}
	long long s = 1;
	for (long long i = 0; i <= n; i++) {
		k[i] = s;
		s *= (i + 1);
		s %= mod;
		if (i != n) {
			sum += p;
			p *= 10;
			sum %= mod;
			p %= mod;
		}
	}
	for (long long i = 1; i <= 9; i++) {
		long long k1 = 1;
		for (long long j = 1; j <= 9; j++) {
			k1 *= k[c[j]];
			k1 %= mod;
		}
		ans += sum * i * c[i] % mod * k[n - 1] % mod * m_pow(k1, mod - 2) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

0