結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー mayoko_mayoko_
提出日時 2016-07-08 22:39:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 99,876 KB
実行使用メモリ 36,608 KB
最終ジャッジ日時 2024-04-21 06:06:00
合計ジャッジ時間 31,290 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
34,816 KB
testcase_01 AC 271 ms
34,944 KB
testcase_02 AC 279 ms
34,944 KB
testcase_03 AC 273 ms
34,944 KB
testcase_04 AC 279 ms
34,944 KB
testcase_05 AC 275 ms
34,816 KB
testcase_06 AC 282 ms
34,816 KB
testcase_07 AC 284 ms
34,816 KB
testcase_08 AC 286 ms
34,816 KB
testcase_09 AC 279 ms
35,072 KB
testcase_10 AC 279 ms
34,816 KB
testcase_11 AC 279 ms
35,072 KB
testcase_12 AC 275 ms
34,816 KB
testcase_13 AC 295 ms
35,584 KB
testcase_14 AC 289 ms
34,944 KB
testcase_15 AC 282 ms
34,944 KB
testcase_16 AC 282 ms
34,816 KB
testcase_17 AC 286 ms
35,072 KB
testcase_18 AC 293 ms
36,096 KB
testcase_19 AC 281 ms
34,816 KB
testcase_20 AC 285 ms
34,816 KB
testcase_21 AC 280 ms
34,816 KB
testcase_22 AC 281 ms
34,944 KB
testcase_23 AC 279 ms
34,944 KB
testcase_24 AC 288 ms
34,816 KB
testcase_25 AC 269 ms
34,784 KB
testcase_26 AC 280 ms
34,944 KB
testcase_27 AC 280 ms
34,944 KB
testcase_28 AC 286 ms
34,816 KB
testcase_29 AC 278 ms
34,944 KB
testcase_30 AC 285 ms
34,944 KB
testcase_31 AC 275 ms
34,944 KB
testcase_32 AC 273 ms
35,072 KB
testcase_33 AC 275 ms
34,944 KB
testcase_34 AC 276 ms
34,816 KB
testcase_35 AC 276 ms
34,944 KB
testcase_36 AC 278 ms
34,944 KB
testcase_37 AC 276 ms
34,816 KB
testcase_38 AC 282 ms
34,944 KB
testcase_39 AC 281 ms
34,844 KB
testcase_40 AC 277 ms
34,816 KB
testcase_41 AC 281 ms
35,072 KB
testcase_42 AC 276 ms
34,944 KB
testcase_43 AC 285 ms
34,816 KB
testcase_44 AC 282 ms
34,912 KB
testcase_45 AC 275 ms
34,944 KB
testcase_46 AC 281 ms
34,944 KB
testcase_47 AC 277 ms
34,944 KB
testcase_48 AC 282 ms
34,816 KB
testcase_49 AC 299 ms
36,224 KB
testcase_50 AC 279 ms
34,944 KB
testcase_51 AC 287 ms
34,944 KB
testcase_52 AC 281 ms
35,072 KB
testcase_53 AC 282 ms
34,944 KB
testcase_54 AC 290 ms
35,072 KB
testcase_55 AC 282 ms
34,816 KB
testcase_56 AC 279 ms
34,816 KB
testcase_57 AC 293 ms
35,456 KB
testcase_58 AC 296 ms
35,712 KB
testcase_59 AC 295 ms
35,712 KB
testcase_60 AC 289 ms
34,944 KB
testcase_61 AC 306 ms
36,608 KB
testcase_62 AC 283 ms
35,328 KB
testcase_63 AC 298 ms
35,840 KB
testcase_64 AC 287 ms
35,200 KB
testcase_65 AC 285 ms
35,072 KB
testcase_66 AC 292 ms
35,072 KB
testcase_67 AC 290 ms
35,072 KB
testcase_68 AC 280 ms
35,200 KB
testcase_69 AC 284 ms
35,072 KB
testcase_70 AC 283 ms
34,944 KB
testcase_71 AC 283 ms
34,944 KB
testcase_72 AC 281 ms
34,944 KB
testcase_73 AC 275 ms
34,944 KB
testcase_74 AC 284 ms
34,816 KB
testcase_75 AC 278 ms
34,944 KB
testcase_76 AC 280 ms
34,816 KB
testcase_77 AC 281 ms
35,072 KB
testcase_78 AC 277 ms
34,816 KB
testcase_79 AC 275 ms
34,944 KB
testcase_80 AC 279 ms
34,944 KB
testcase_81 AC 279 ms
34,944 KB
testcase_82 AC 274 ms
34,816 KB
testcase_83 AC 280 ms
34,688 KB
testcase_84 AC 283 ms
34,944 KB
testcase_85 AC 284 ms
34,944 KB
testcase_86 AC 282 ms
34,944 KB
testcase_87 AC 279 ms
34,944 KB
testcase_88 AC 279 ms
34,944 KB
testcase_89 AC 287 ms
35,200 KB
testcase_90 AC 295 ms
35,584 KB
testcase_91 AC 301 ms
36,096 KB
testcase_92 AC 286 ms
35,072 KB
testcase_93 AC 293 ms
35,584 KB
testcase_94 AC 279 ms
34,944 KB
testcase_95 AC 285 ms
35,584 KB
testcase_96 AC 289 ms
35,584 KB
testcase_97 AC 291 ms
35,328 KB
testcase_98 AC 279 ms
35,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;


ll mod_pow(ll x, ll p, ll MOD) {
    ll a = 1;
    while (p) {
        if (p%2) a = a*x%MOD;
        x = x*x%MOD;
        p/=2;
    }
    return a;
}

// mod_inverse
ll mod_inverse(ll a, ll m) {
    return mod_pow(a, m-2, m);
}

const int MAXM = 1001000;
const int MOD = 1e9+7;
int H[MAXM];
ll fact[2*MAXM], rfact[2*MAXM];
int M, K;

ll nCr(int n, int r) {
    ll ret = fact[n];
    (ret *= rfact[r]) %= MOD;
    (ret *= rfact[n-r]) %= MOD;
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact[0] = rfact[0] = 1;
    for (int i = 1; i < 2*MAXM; i++) {
        fact[i] = (fact[i-1]*i)%MOD;
        rfact[i] = mod_inverse(fact[i], MOD);
    }
    cin >> M;
    int sum = 0;
    while (cin >> H[K]) {
        sum += H[K++];
    }
    int rest = M-sum;
    rest -= K-1;
    if (rest < 0) {
        cout << "NA" << endl;
        return 0;
    }
    if (K == 1 && H[0] == 0) {
        cout << 1 << endl;
        return 0;
    }
    cout << nCr(rest+K, K) << endl;
    return 0;
}
0