結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー ktr216ktr216
提出日時 2021-07-30 20:55:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 948 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 167,840 KB
実行使用メモリ 4,736 KB
最終ジャッジ日時 2023-10-14 03:11:46
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<int> c(9);
    rep(i, 0, 9) cin >> c[i];
    vector<ll> f(N + 1, 1);
    ll ans = 0, b = 0, MOD = 1e9 + 7;
    rep(i, 0, N) {
        b = (b * 10 + 1) % MOD;
        f[i + 1] = f[i] * (i + 1) % MOD;
    }
    rep(i, 0, 9) {
        if (c[i] == 0) continue;
        ll d = f[N - 1];
        rep(j, 0, 9) {
            if (i == j) {
                d = d * mod_pow(f[c[j] - 1], MOD - 2, MOD) % MOD;
            } else {
                d = d * mod_pow(f[c[j]], MOD - 2, MOD) % MOD;
            }
        }
        ans += d * (i + 1) % MOD * b % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}
0