結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー ShibuyapShibuyap
提出日時 2022-01-15 17:26:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 199,960 KB
実行使用メモリ 31,232 KB
最終ジャッジ日時 2023-08-14 02:02:40
合計ジャッジ時間 7,590 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
29,380 KB
testcase_01 AC 21 ms
29,436 KB
testcase_02 AC 20 ms
29,568 KB
testcase_03 AC 20 ms
29,360 KB
testcase_04 AC 22 ms
29,384 KB
testcase_05 AC 20 ms
29,376 KB
testcase_06 AC 20 ms
29,436 KB
testcase_07 AC 20 ms
29,380 KB
testcase_08 AC 20 ms
29,312 KB
testcase_09 AC 24 ms
29,560 KB
testcase_10 AC 24 ms
29,500 KB
testcase_11 AC 27 ms
29,568 KB
testcase_12 AC 23 ms
29,508 KB
testcase_13 AC 39 ms
30,092 KB
testcase_14 AC 26 ms
29,584 KB
testcase_15 AC 22 ms
29,480 KB
testcase_16 AC 24 ms
29,440 KB
testcase_17 AC 26 ms
29,512 KB
testcase_18 AC 57 ms
31,232 KB
testcase_19 AC 21 ms
29,328 KB
testcase_20 AC 20 ms
29,480 KB
testcase_21 AC 20 ms
29,320 KB
testcase_22 AC 21 ms
29,380 KB
testcase_23 AC 20 ms
29,376 KB
testcase_24 AC 20 ms
29,460 KB
testcase_25 AC 20 ms
29,376 KB
testcase_26 AC 20 ms
29,476 KB
testcase_27 AC 20 ms
29,384 KB
testcase_28 AC 20 ms
29,388 KB
testcase_29 AC 21 ms
29,540 KB
testcase_30 AC 20 ms
29,524 KB
testcase_31 AC 21 ms
29,384 KB
testcase_32 AC 20 ms
29,396 KB
testcase_33 AC 19 ms
29,416 KB
testcase_34 AC 20 ms
29,364 KB
testcase_35 AC 21 ms
29,320 KB
testcase_36 AC 21 ms
29,484 KB
testcase_37 AC 20 ms
29,332 KB
testcase_38 AC 21 ms
29,376 KB
testcase_39 AC 20 ms
29,332 KB
testcase_40 AC 21 ms
29,384 KB
testcase_41 AC 20 ms
29,404 KB
testcase_42 AC 22 ms
29,332 KB
testcase_43 AC 21 ms
29,388 KB
testcase_44 AC 21 ms
29,376 KB
testcase_45 AC 21 ms
29,392 KB
testcase_46 AC 21 ms
29,360 KB
testcase_47 AC 22 ms
29,420 KB
testcase_48 AC 21 ms
29,408 KB
testcase_49 AC 61 ms
31,076 KB
testcase_50 AC 24 ms
29,436 KB
testcase_51 AC 22 ms
29,500 KB
testcase_52 AC 28 ms
29,528 KB
testcase_53 AC 24 ms
29,496 KB
testcase_54 AC 34 ms
29,696 KB
testcase_55 AC 21 ms
29,356 KB
testcase_56 AC 24 ms
29,544 KB
testcase_57 AC 37 ms
30,096 KB
testcase_58 AC 53 ms
31,172 KB
testcase_59 AC 44 ms
30,032 KB
testcase_60 AC 32 ms
29,696 KB
testcase_61 AC 72 ms
31,144 KB
testcase_62 AC 33 ms
29,712 KB
testcase_63 AC 56 ms
31,144 KB
testcase_64 AC 31 ms
29,456 KB
testcase_65 AC 26 ms
29,508 KB
testcase_66 AC 31 ms
29,972 KB
testcase_67 AC 30 ms
29,644 KB
testcase_68 AC 30 ms
29,688 KB
testcase_69 AC 21 ms
29,328 KB
testcase_70 AC 20 ms
29,332 KB
testcase_71 AC 20 ms
29,416 KB
testcase_72 AC 21 ms
29,384 KB
testcase_73 AC 21 ms
29,376 KB
testcase_74 AC 22 ms
29,436 KB
testcase_75 AC 21 ms
29,616 KB
testcase_76 AC 21 ms
29,408 KB
testcase_77 AC 20 ms
29,380 KB
testcase_78 AC 20 ms
29,472 KB
testcase_79 AC 20 ms
29,400 KB
testcase_80 AC 21 ms
29,332 KB
testcase_81 AC 20 ms
29,460 KB
testcase_82 AC 21 ms
29,316 KB
testcase_83 AC 20 ms
29,396 KB
testcase_84 AC 21 ms
29,532 KB
testcase_85 AC 21 ms
29,400 KB
testcase_86 AC 20 ms
29,316 KB
testcase_87 AC 21 ms
29,460 KB
testcase_88 AC 22 ms
29,380 KB
testcase_89 AC 34 ms
29,656 KB
testcase_90 AC 42 ms
30,100 KB
testcase_91 AC 61 ms
31,132 KB
testcase_92 AC 29 ms
29,528 KB
testcase_93 AC 46 ms
30,088 KB
testcase_94 AC 22 ms
29,356 KB
testcase_95 AC 46 ms
30,128 KB
testcase_96 AC 42 ms
30,024 KB
testcase_97 AC 43 ms
30,032 KB
testcase_98 AC 31 ms
29,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define MAX_N 200005

const int MAX = 1110000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1]            = 1;
    for (int i = 2; i < MAX; 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;
}

long long FINV(int n) {
    if (n < 0) return 0;
    return finv[n];
}

int main() {
    COMinit();
    int m;
    cin >> m;
    vector<int> v;
    int h;
    while (cin >> h) {
        v.push_back(h);
    }

    int n = v.size();

    int sum = 0;
    rep(i, n) sum += v[i];
    sum += n - 1;
    if (sum > m) {
        cout << "NA" << endl;
        return 0;
    }

    if (v[0] == 0) {
        cout << 1 << endl;
        return 0;
    }

    rep(i, n) {
        m -= v[i];
    }
    m++;

    int ans = COM(m, n);

    cout << ans << endl;
    return 0;
}
0