結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー ぷらぷら
提出日時 2021-07-30 20:43:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 201,052 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-10-14 03:01:01
合計ジャッジ時間 3,395 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,036 KB
testcase_01 AC 7 ms
8,036 KB
testcase_02 AC 6 ms
8,300 KB
testcase_03 AC 6 ms
8,348 KB
testcase_04 AC 13 ms
8,036 KB
testcase_05 AC 8 ms
8,032 KB
testcase_06 AC 8 ms
8,056 KB
testcase_07 AC 15 ms
8,064 KB
testcase_08 AC 13 ms
8,216 KB
testcase_09 AC 13 ms
8,088 KB
testcase_10 AC 13 ms
8,072 KB
testcase_11 AC 11 ms
8,096 KB
testcase_12 AC 13 ms
8,048 KB
testcase_13 AC 13 ms
8,032 KB
testcase_14 AC 11 ms
8,120 KB
testcase_15 AC 14 ms
8,024 KB
testcase_16 AC 14 ms
8,036 KB
testcase_17 AC 20 ms
8,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 1000000007;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    COMinit();
    int N;
    cin >> N;
    vector<int>tmp(9);
    long long ans = 0;
    for(int i = 0; i < 9; i++) {
        cin >> tmp[i];
    }
    for(int i = 0; i < 9; i++) {
        long long tmp2 = COM(N-1,tmp[i]-1);
        long long sum = N-tmp[i];
        for(int j = 0; j < 9; j++) {
            if(i != j) {
                tmp2 *= COM(sum,tmp[j]);
                tmp2 %= mod;
                sum -= tmp[j];
            }
        }
        sum = 1;
        for(int j = 0; j < N; j++) {
            ans += sum*tmp2%mod*(i+1)%mod;
            ans %= mod;
            sum *= 10;
            sum %= mod;
        }
    }
    cout << ans << endl;
}
0