結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー sk461sk461
提出日時 2021-07-30 22:49:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,831 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 107,784 KB
実行使用メモリ 7,756 KB
最終ジャッジ日時 2023-10-14 07:15:07
合計ジャッジ時間 2,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,652 KB
testcase_01 AC 8 ms
7,728 KB
testcase_02 AC 8 ms
7,700 KB
testcase_03 AC 8 ms
7,720 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

// #include <atcoder>
// using namespace atcoder;
// using mint = modint1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Bdouble = mp::number<mp::cpp_dec_float<32>>;

const int MOD = 1000000007;

vector<ll> fac(200200), finv(200200), inv(200200);
bool is_preprocessing_already_done = 0;

void preprocessing() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 200200; 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;
    }
}

ll comb(int n, int k) {
    if (!is_preprocessing_already_done) {
        preprocessing();
        is_preprocessing_already_done = 1;
    }
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    ll cntfinv = 1;
    for (ll i = 0; i < 9; i++) {
        ll c;
        cin >> c;
        ll cnt = i + 1;
        for (int j = 0; j < n - 1; j++) {
            cnt *= 10;
            cnt += i + 1;
        }
        ans += cnt * comb(n - 1, n - c);
        ans %= MOD;
        cntfinv *= finv[c];
    }
    ans *= fac[n - 1] * cntfinv;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}
0