結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー atjh16atjh16
提出日時 2021-09-08 21:17:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 165,336 KB
実行使用メモリ 4,968 KB
最終ジャッジ日時 2023-08-27 06:27:26
合計ジャッジ時間 2,927 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long n, m = 0;
long long c[9], g[200001];
const long long M = 1e9 + 7;

long long powm(long long a, long long b) {
	long long u = 1, v = a;

	while (b > 0) {
		if (b & 1)
			u = u * v % M;

		b >>= 1;
		v = v * v % M;
	}

	return u;
}

int main()
{
	cin >> n;

	for (int i = 0; i < 9; i++)
		cin >> c[i];

	g[0] = 1;

	for (int i = 1; i < n; i++)
		g[i] = g[i - 1] * i % M;

	for (int i = 0; i < 9; i++) {
		if (c[i] > 0) {
			long long u = (i + 1) * g[n - 1] % M;

			for (int j = 0; j < 9; j++) {
				if (j != i)
					u = u * powm(g[c[j]], M - 2) % M;
				else
					u = u * powm(g[c[j] - 1], M - 2) % M;
			}

			m = (m + u) % M;
		}
	}

	m = m * (powm(10, n) - 1) % M * powm(9, M - 2) % M;
	cout << m << endl;
}
0