結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー SSRSSSRS
提出日時 2021-07-30 20:33:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,192 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 170,196 KB
実行使用メモリ 6,324 KB
最終ジャッジ日時 2023-10-14 02:47:46
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,356 KB
testcase_04 AC 19 ms
4,588 KB
testcase_05 AC 5 ms
4,352 KB
testcase_06 AC 6 ms
4,352 KB
testcase_07 AC 25 ms
5,232 KB
testcase_08 AC 20 ms
4,596 KB
testcase_09 AC 23 ms
4,904 KB
testcase_10 AC 20 ms
4,568 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 20 ms
4,544 KB
testcase_13 AC 22 ms
4,788 KB
testcase_14 AC 16 ms
4,700 KB
testcase_15 AC 23 ms
4,840 KB
testcase_16 AC 23 ms
5,100 KB
testcase_17 AC 42 ms
6,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
int main(){
  int N;
  cin >> N;
  vector<int> c(9);
  for (int i = 0; i < 9; i++){
    cin >> c[i];
  }
  long long s = 0;
  for (int i = 0; i < 9; i++){
    s += (i + 1) * c[i];
  }
  s *= modinv(N);
  s %= MOD;
  long long s2 = 0;
  for (int i = 0; i < N; i++){
    s2 *= 10;
    s2++;
    s2 %= MOD;
  }
  long long a = s * s2 % MOD;
  a *= modfact(N);
  a %= MOD;
  for (int i = 0; i < 9; i++){
    a *= modfactinv(c[i]);
    a %= MOD;
  }
  cout << a << endl;
}
0