結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-21 22:00:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 3,135 ms
コンパイル使用メモリ 202,388 KB
実行使用メモリ 18,796 KB
最終ジャッジ日時 2023-09-11 17:04:09
合計ジャッジ時間 4,747 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
18,644 KB
testcase_01 AC 18 ms
18,756 KB
testcase_02 AC 18 ms
18,516 KB
testcase_03 AC 18 ms
18,764 KB
testcase_04 AC 18 ms
18,476 KB
testcase_05 AC 18 ms
18,624 KB
testcase_06 AC 17 ms
18,476 KB
testcase_07 AC 17 ms
18,328 KB
testcase_08 AC 18 ms
18,516 KB
testcase_09 AC 17 ms
18,524 KB
testcase_10 AC 18 ms
18,592 KB
testcase_11 AC 18 ms
18,320 KB
testcase_12 AC 18 ms
18,580 KB
testcase_13 AC 18 ms
18,528 KB
testcase_14 AC 17 ms
18,692 KB
testcase_15 AC 17 ms
18,592 KB
testcase_16 AC 18 ms
18,592 KB
testcase_17 AC 18 ms
18,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll modc=1e9+7, MAX=1000000;
vector<ll> f, finv;

ll mod_exp(ll b, ll e, ll m){
    if (e > 0 && b == 0) return 0;
    ll ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}
ll inv(ll x){
    ll ans = 1, e = modc-2;
    x %= modc;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * x) % modc;
        e = e >> 1LL;
        x = (x*x) % modc;
    }

    return ans;
}

void init(){
    f.resize(MAX+1); finv.resize(MAX+1);
    f[0] = 1;
    for (int i=1; i<=MAX; i++) f[i] = (f[i-1]*i) % modc;
    finv[MAX] = inv(f[MAX]);
    for (int i=MAX-1; i>=0; i--) finv[i] = (finv[i+1] * (i+1)) % modc;
}

ll P(ll n, ll k){
    if (n < k || k < 0) return 0;

    return (f[n] * finv[n-k]) % modc;
}

int main(){

    init();
    ll N, ans=0, cnt;
    cin >> N;
    vector<ll> c(10);
    for (int i=1; i<=9; i++) cin >> c[i];

    for (int i=1; i<=9; i++){
        if (c[i] == 0) continue;
        cnt = P(N-1, N-1);
        for (int j=1; j<=9; j++){
            if (i == j){
                cnt *= inv(P(c[j]-1, c[j]-1));
                cnt %= modc;
            }
            else{
                cnt *= inv(P(c[j], c[j]));
                cnt %= modc;
            }
        }
        ans += (cnt*i) % modc;
        ans %= modc;
    }

    cnt = (mod_exp(10, N, modc) - 1) * inv(9) % modc;
    cout << (cnt * ans) % modc << endl;

    return 0;
}
0