結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー kyunakyuna
提出日時 2019-08-19 21:17:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 3,649 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 76,836 KB
実行使用メモリ 17,304 KB
最終ジャッジ日時 2024-04-15 10:02:29
合計ジャッジ時間 7,163 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
15,104 KB
testcase_01 AC 22 ms
14,900 KB
testcase_02 AC 23 ms
15,076 KB
testcase_03 AC 23 ms
14,900 KB
testcase_04 AC 22 ms
14,972 KB
testcase_05 AC 22 ms
14,968 KB
testcase_06 AC 23 ms
15,008 KB
testcase_07 AC 22 ms
15,040 KB
testcase_08 AC 21 ms
14,908 KB
testcase_09 AC 28 ms
15,372 KB
testcase_10 AC 26 ms
15,364 KB
testcase_11 AC 30 ms
15,404 KB
testcase_12 AC 27 ms
15,160 KB
testcase_13 AC 47 ms
16,152 KB
testcase_14 AC 30 ms
15,376 KB
testcase_15 AC 25 ms
15,116 KB
testcase_16 AC 25 ms
15,160 KB
testcase_17 AC 29 ms
15,288 KB
testcase_18 AC 69 ms
17,304 KB
testcase_19 AC 22 ms
14,984 KB
testcase_20 AC 22 ms
14,904 KB
testcase_21 AC 21 ms
14,908 KB
testcase_22 AC 23 ms
14,972 KB
testcase_23 AC 22 ms
15,016 KB
testcase_24 AC 22 ms
14,988 KB
testcase_25 AC 23 ms
15,032 KB
testcase_26 AC 24 ms
15,076 KB
testcase_27 AC 21 ms
14,996 KB
testcase_28 AC 22 ms
14,956 KB
testcase_29 AC 22 ms
14,988 KB
testcase_30 AC 22 ms
14,964 KB
testcase_31 AC 22 ms
14,972 KB
testcase_32 AC 22 ms
14,972 KB
testcase_33 AC 22 ms
14,992 KB
testcase_34 AC 22 ms
14,960 KB
testcase_35 AC 22 ms
15,032 KB
testcase_36 AC 22 ms
14,904 KB
testcase_37 AC 22 ms
15,088 KB
testcase_38 AC 22 ms
15,064 KB
testcase_39 AC 22 ms
14,908 KB
testcase_40 AC 22 ms
14,920 KB
testcase_41 AC 23 ms
15,016 KB
testcase_42 AC 22 ms
15,084 KB
testcase_43 AC 22 ms
14,916 KB
testcase_44 AC 22 ms
14,964 KB
testcase_45 AC 21 ms
14,968 KB
testcase_46 AC 22 ms
14,928 KB
testcase_47 AC 21 ms
15,072 KB
testcase_48 AC 22 ms
14,928 KB
testcase_49 AC 72 ms
17,180 KB
testcase_50 AC 25 ms
15,128 KB
testcase_51 AC 25 ms
15,040 KB
testcase_52 AC 32 ms
15,444 KB
testcase_53 AC 25 ms
15,168 KB
testcase_54 AC 34 ms
15,400 KB
testcase_55 AC 22 ms
14,924 KB
testcase_56 AC 26 ms
15,228 KB
testcase_57 AC 43 ms
16,152 KB
testcase_58 AC 64 ms
17,176 KB
testcase_59 AC 55 ms
16,284 KB
testcase_60 AC 36 ms
15,608 KB
testcase_61 AC 91 ms
17,304 KB
testcase_62 AC 36 ms
15,712 KB
testcase_63 AC 67 ms
17,176 KB
testcase_64 AC 35 ms
15,396 KB
testcase_65 AC 29 ms
15,372 KB
testcase_66 AC 35 ms
15,564 KB
testcase_67 AC 34 ms
15,708 KB
testcase_68 AC 34 ms
15,808 KB
testcase_69 AC 22 ms
14,920 KB
testcase_70 AC 22 ms
14,892 KB
testcase_71 AC 22 ms
14,972 KB
testcase_72 AC 21 ms
14,924 KB
testcase_73 AC 22 ms
14,924 KB
testcase_74 AC 22 ms
15,172 KB
testcase_75 AC 22 ms
14,988 KB
testcase_76 AC 23 ms
15,016 KB
testcase_77 AC 22 ms
14,988 KB
testcase_78 AC 22 ms
14,964 KB
testcase_79 AC 22 ms
15,144 KB
testcase_80 AC 22 ms
15,012 KB
testcase_81 AC 21 ms
14,920 KB
testcase_82 AC 22 ms
14,908 KB
testcase_83 AC 22 ms
14,972 KB
testcase_84 AC 22 ms
15,088 KB
testcase_85 AC 23 ms
15,068 KB
testcase_86 AC 23 ms
14,916 KB
testcase_87 AC 22 ms
15,008 KB
testcase_88 AC 22 ms
14,980 KB
testcase_89 AC 39 ms
15,632 KB
testcase_90 AC 50 ms
16,284 KB
testcase_91 AC 71 ms
17,304 KB
testcase_92 AC 29 ms
15,284 KB
testcase_93 AC 52 ms
16,284 KB
testcase_94 AC 23 ms
15,028 KB
testcase_95 AC 54 ms
16,152 KB
testcase_96 AC 48 ms
16,280 KB
testcase_97 AC 46 ms
16,156 KB
testcase_98 AC 34 ms
15,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;


//---------------------------------------------------------------
template<int MOD> struct ModInt { int x;
    explicit operator bool() const { return !!x; }
    ModInt(int v = 0) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt(long long v) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt &operator+=(const ModInt &r) { if ((x += r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt &r) { if ((x += MOD - r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(const ModInt &r) { x = 1LL * x * r.x % MOD; return *this; }
    ModInt &operator/=(const ModInt &r) { return *this *= r.inv(); }
    ModInt operator-() const { return x ? ModInt(MOD - x) : ModInt(x); }
    ModInt operator+(const ModInt &r) const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt &r) const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt &r) const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt &r) const { return ModInt(*this) /= r; }
    ModInt inv() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u); } // x.pow(MOD-2)
    ModInt pow(long long k) const { ModInt r(1), a(x);
        while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
    bool operator==(const ModInt r) const { return x == r.x; }
    bool operator!=(const ModInt r) const { return x != r.x; }
    bool operator< (const ModInt r) const { return x <  r.x; }
    friend ostream& operator<<(ostream &os, const ModInt<MOD>& a) { return os << a.x; }
    friend istream& operator>>(istream &is, ModInt<MOD>& a) { return is >> a.x; }
};
template<typename T, int SZ> struct Comb { vector<T> _fac, _ifac, _inv;
    Comb() : _fac(SZ + 1), _ifac(SZ + 1), _inv(SZ + 1) {
        _fac[0] = _ifac[SZ] = _inv[0] = 1;
        for (int i = 1; i <= SZ; i++) _fac[i] = _fac[i - 1] * i;
        _ifac[SZ] /= _fac[SZ];
        for (int i = SZ - 1; i >= 0; i--) _ifac[i] = _ifac[i + 1] * (i + 1);
        for (int i = 1; i <= SZ; i++) _inv[i] = _ifac[i] * _fac[i - 1]; }
    T inv(int n) { return n < 0 ? T(0) : _inv[n]; }
    T fac(int n) { return n < 0 ? T(0) : _fac[n]; }
    T ifac(int n) { return n < 0 ? T(0) : _ifac[n]; }
    T P(int a, int b) { return (b < 0 || a < b) ? T(0) : _fac[a] * _ifac[a - b]; }
    T C(int a, int b) { return b < 0 ? T(0) : P(a, b) * _ifac[b]; }
    T H(int n, int k) { if (n < 0 || k < 0) return T(0);
        return k == 0 ? T(1) : C(n + k - 1, k); }
    T S(int n, int k) { T r = 0;
        for (int i = 0; i <= k; i++) {
            T t = C(k, i) * T(i).pow(n); r += ((k - i) & 1 ? -t : t);
        }
        return r * _ifac[k];
    }
    T B(int n, int k) {
        if (n == 0) return T(1);
        T r = 0; k = min(k, n);
        vector<T> dp(k + 1); dp[0] = T(1);
        for (int i = 1; i <= k; i++) dp[i] = dp[i - 1] + (i & 1 ? -_ifac[i] : _ifac[i]);
        for (int i = 1; i <= k; i++) r += T(i).pow(n) * _ifac[i] * dp[k - i];
        return r;
    }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 1000000> com;
    int m; cin >> m;
    vector<int> h;
    int sum = 0, tmp;
    while (cin >> tmp) sum += tmp, h.emplace_back(tmp);
    if (h[0] == 0) {
        cout << 1 << endl;
        return 0;
    }
    int a = h.size() + 1;
    int b = m - (sum + h.size() - 1);
    if (b < 0) {
        cout << "NA" << endl;
        return 0;
    }
    cout << com.H(a, b) << endl;
    return 0;
}
0