結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー | kyuna |
提出日時 | 2019-08-19 21:17:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 3,649 bytes |
コンパイル時間 | 731 ms |
コンパイル使用メモリ | 75,808 KB |
実行使用メモリ | 17,304 KB |
最終ジャッジ日時 | 2024-10-05 03:39:45 |
合計ジャッジ時間 | 6,128 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
15,112 KB |
testcase_01 | AC | 18 ms
14,980 KB |
testcase_02 | AC | 18 ms
14,936 KB |
testcase_03 | AC | 17 ms
14,944 KB |
testcase_04 | AC | 16 ms
14,980 KB |
testcase_05 | AC | 18 ms
14,956 KB |
testcase_06 | AC | 19 ms
15,048 KB |
testcase_07 | AC | 19 ms
14,944 KB |
testcase_08 | AC | 17 ms
14,912 KB |
testcase_09 | AC | 24 ms
15,360 KB |
testcase_10 | AC | 23 ms
15,140 KB |
testcase_11 | AC | 26 ms
15,268 KB |
testcase_12 | AC | 23 ms
15,176 KB |
testcase_13 | AC | 43 ms
16,156 KB |
testcase_14 | AC | 27 ms
15,284 KB |
testcase_15 | AC | 22 ms
15,076 KB |
testcase_16 | AC | 24 ms
15,180 KB |
testcase_17 | AC | 25 ms
15,440 KB |
testcase_18 | AC | 64 ms
17,176 KB |
testcase_19 | AC | 20 ms
14,884 KB |
testcase_20 | AC | 19 ms
14,884 KB |
testcase_21 | AC | 20 ms
14,880 KB |
testcase_22 | AC | 19 ms
15,032 KB |
testcase_23 | AC | 18 ms
15,040 KB |
testcase_24 | AC | 18 ms
14,980 KB |
testcase_25 | AC | 19 ms
15,008 KB |
testcase_26 | AC | 20 ms
14,988 KB |
testcase_27 | AC | 19 ms
14,984 KB |
testcase_28 | AC | 19 ms
14,940 KB |
testcase_29 | AC | 18 ms
14,932 KB |
testcase_30 | AC | 18 ms
14,908 KB |
testcase_31 | AC | 19 ms
14,900 KB |
testcase_32 | AC | 19 ms
15,012 KB |
testcase_33 | AC | 18 ms
14,944 KB |
testcase_34 | AC | 19 ms
15,052 KB |
testcase_35 | AC | 20 ms
15,020 KB |
testcase_36 | AC | 19 ms
14,908 KB |
testcase_37 | AC | 19 ms
14,900 KB |
testcase_38 | AC | 19 ms
14,940 KB |
testcase_39 | AC | 18 ms
15,012 KB |
testcase_40 | AC | 18 ms
14,984 KB |
testcase_41 | AC | 18 ms
14,916 KB |
testcase_42 | AC | 21 ms
14,932 KB |
testcase_43 | AC | 21 ms
14,944 KB |
testcase_44 | AC | 21 ms
14,944 KB |
testcase_45 | AC | 19 ms
14,908 KB |
testcase_46 | AC | 19 ms
15,000 KB |
testcase_47 | AC | 18 ms
14,984 KB |
testcase_48 | AC | 17 ms
14,948 KB |
testcase_49 | AC | 65 ms
17,176 KB |
testcase_50 | AC | 22 ms
15,124 KB |
testcase_51 | AC | 22 ms
15,108 KB |
testcase_52 | AC | 28 ms
15,316 KB |
testcase_53 | AC | 24 ms
15,132 KB |
testcase_54 | AC | 31 ms
15,332 KB |
testcase_55 | AC | 19 ms
14,912 KB |
testcase_56 | AC | 23 ms
15,288 KB |
testcase_57 | AC | 39 ms
16,152 KB |
testcase_58 | AC | 56 ms
17,304 KB |
testcase_59 | AC | 47 ms
16,152 KB |
testcase_60 | AC | 31 ms
15,608 KB |
testcase_61 | AC | 85 ms
17,176 KB |
testcase_62 | AC | 33 ms
15,640 KB |
testcase_63 | AC | 58 ms
17,304 KB |
testcase_64 | AC | 30 ms
15,300 KB |
testcase_65 | AC | 24 ms
15,328 KB |
testcase_66 | AC | 30 ms
15,556 KB |
testcase_67 | AC | 29 ms
15,580 KB |
testcase_68 | AC | 31 ms
15,552 KB |
testcase_69 | AC | 20 ms
14,992 KB |
testcase_70 | AC | 18 ms
14,880 KB |
testcase_71 | AC | 18 ms
14,924 KB |
testcase_72 | AC | 18 ms
14,876 KB |
testcase_73 | AC | 18 ms
14,916 KB |
testcase_74 | AC | 19 ms
15,096 KB |
testcase_75 | AC | 20 ms
14,948 KB |
testcase_76 | AC | 19 ms
15,012 KB |
testcase_77 | AC | 19 ms
14,912 KB |
testcase_78 | AC | 18 ms
14,940 KB |
testcase_79 | AC | 18 ms
14,928 KB |
testcase_80 | AC | 19 ms
14,900 KB |
testcase_81 | AC | 19 ms
14,912 KB |
testcase_82 | AC | 20 ms
15,060 KB |
testcase_83 | AC | 18 ms
14,976 KB |
testcase_84 | AC | 18 ms
15,080 KB |
testcase_85 | AC | 18 ms
14,988 KB |
testcase_86 | AC | 18 ms
15,016 KB |
testcase_87 | AC | 17 ms
14,980 KB |
testcase_88 | AC | 19 ms
14,976 KB |
testcase_89 | AC | 33 ms
15,588 KB |
testcase_90 | AC | 45 ms
16,152 KB |
testcase_91 | AC | 65 ms
17,180 KB |
testcase_92 | AC | 26 ms
15,428 KB |
testcase_93 | AC | 46 ms
16,148 KB |
testcase_94 | AC | 20 ms
14,952 KB |
testcase_95 | AC | 48 ms
16,152 KB |
testcase_96 | AC | 41 ms
16,276 KB |
testcase_97 | AC | 41 ms
16,152 KB |
testcase_98 | AC | 29 ms
15,700 KB |
ソースコード
#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; }