結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー maguromaguro
提出日時 2022-05-18 15:42:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,362 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 203,916 KB
実行使用メモリ 7,760 KB
最終ジャッジ日時 2023-10-14 23:28:54
合計ジャッジ時間 3,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 12 ms
5,132 KB
testcase_05 AC 4 ms
4,352 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 15 ms
5,920 KB
testcase_08 AC 12 ms
5,248 KB
testcase_09 AC 14 ms
5,508 KB
testcase_10 AC 13 ms
5,244 KB
testcase_11 AC 9 ms
4,356 KB
testcase_12 AC 13 ms
5,192 KB
testcase_13 AC 14 ms
5,400 KB
testcase_14 AC 10 ms
4,652 KB
testcase_15 AC 15 ms
5,348 KB
testcase_16 AC 14 ms
5,528 KB
testcase_17 AC 27 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
constexpr int Inf = 2000000000;
constexpr long long INF= 2000000000000000000;

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T,typename U>
T modpow(T N, U P, T M = -1) {
    if(P < 0) return 0;
    T ret = 1;
    if(M != -1) ret %= M;
    while(P) {
        if(P & 1) {
            if(M == -1) ret *= N;
            else ret = ret * N % M;
        }
        P /= 2;
        if(M == -1) N *= N;
        else N = N * N % M;
    }
    return ret;
}

constexpr long long MOD = 1000000007;

struct Comb {
    int size;
    long long mod;
    std::vector<long long> factorial;
    std::vector<long long> inversion_factorial;
    std::vector<long long> inversion;

    Comb(int n,long long mod): size(n),mod(mod) {
        factorial.resize(n + 1);
        inversion_factorial.resize(n + 1);
        inversion.resize(n + 1);
        factorial[0] = factorial[1] = 1;
        inversion_factorial[0] = inversion_factorial[1] = 1;
        inversion[1] = 1;
        for (long long i = 2; i <= n; i++) {
            factorial[i] = factorial[i - 1] * i % mod;
            inversion[i] = mod - inversion[mod % i] * (mod / i) % mod;
            inversion_factorial[i] = inversion_factorial[i - 1] * inversion[i] % mod;
        }
    }

    long long comb(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return factorial[n] * (inversion_factorial[k] * inversion_factorial[n - k] % mod) % mod;
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> vec(9);
    for(auto& x: vec) cin >> x;

    Comb comb(n,MOD);

    long long base = 0;
    for(int i = 0;i < n;i++) {
        base += modpow(10ll,i,MOD);
        base %= MOD;
    }

    long long ret = 0;
    for(int i = 0;i < 10;i++) {
        if(vec[i] != 0) {
            long long res = 1;
            vec[i]--;
            int remain = n - 1;
            for(int j = 0;j < 10;j++) {
                res *= comb.comb(remain,vec[j]);
                res %= MOD;
                remain -= vec[j];
            }
            vec[i]++;
            ret += res * base % MOD * (i + 1) % MOD;
            ret %= MOD;
        }
    }

    cout << ret << endl;
}
0