結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー face4face4
提出日時 2018-11-15 13:25:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,305 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 71,000 KB
実行使用メモリ 17,976 KB
最終ジャッジ日時 2023-08-26 01:14:58
合計ジャッジ時間 6,308 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 13 ms
13,044 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 9 ms
8,992 KB
testcase_07 AC 17 ms
17,740 KB
testcase_08 AC 10 ms
9,692 KB
testcase_09 AC 19 ms
15,500 KB
testcase_10 AC 7 ms
5,004 KB
testcase_11 AC 22 ms
15,568 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 38 ms
17,892 KB
testcase_14 AC 12 ms
5,220 KB
testcase_15 AC 7 ms
5,188 KB
testcase_16 AC 11 ms
8,568 KB
testcase_17 AC 18 ms
11,672 KB
testcase_18 AC 54 ms
12,900 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 57 ms
13,456 KB
testcase_50 AC 8 ms
5,872 KB
testcase_51 AC 5 ms
4,380 KB
testcase_52 AC 23 ms
14,980 KB
testcase_53 AC 9 ms
5,856 KB
testcase_54 AC 27 ms
17,428 KB
testcase_55 AC 5 ms
5,480 KB
testcase_56 AC 6 ms
4,380 KB
testcase_57 AC 28 ms
10,248 KB
testcase_58 AC 50 ms
16,376 KB
testcase_59 AC 41 ms
13,408 KB
testcase_60 AC 19 ms
6,800 KB
testcase_61 AC 75 ms
17,212 KB
testcase_62 AC 23 ms
10,804 KB
testcase_63 AC 50 ms
13,720 KB
testcase_64 AC 26 ms
16,004 KB
testcase_65 AC 10 ms
5,260 KB
testcase_66 AC 16 ms
5,644 KB
testcase_67 AC 20 ms
11,072 KB
testcase_68 AC 28 ms
17,008 KB
testcase_69 AC 14 ms
13,580 KB
testcase_70 AC 11 ms
10,908 KB
testcase_71 AC 8 ms
7,492 KB
testcase_72 AC 16 ms
15,884 KB
testcase_73 AC 8 ms
8,220 KB
testcase_74 AC 9 ms
7,708 KB
testcase_75 AC 8 ms
8,096 KB
testcase_76 AC 10 ms
10,484 KB
testcase_77 AC 10 ms
10,548 KB
testcase_78 AC 5 ms
5,660 KB
testcase_79 AC 8 ms
7,280 KB
testcase_80 AC 5 ms
5,396 KB
testcase_81 AC 3 ms
4,380 KB
testcase_82 AC 15 ms
15,232 KB
testcase_83 AC 9 ms
8,780 KB
testcase_84 AC 6 ms
5,860 KB
testcase_85 AC 17 ms
16,744 KB
testcase_86 AC 15 ms
15,364 KB
testcase_87 AC 3 ms
4,376 KB
testcase_88 AC 2 ms
4,376 KB
testcase_89 AC 24 ms
9,556 KB
testcase_90 AC 41 ms
17,976 KB
testcase_91 AC 56 ms
13,956 KB
testcase_92 AC 12 ms
5,912 KB
testcase_93 AC 39 ms
13,164 KB
testcase_94 AC 13 ms
12,996 KB
testcase_95 AC 38 ms
10,156 KB
testcase_96 AC 38 ms
17,800 KB
testcase_97 AC 35 ms
15,460 KB
testcase_98 AC 26 ms
15,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k);
    }
};

int main(){
    int m;
    cin >> m;

    ModComb mc(m);

    int a, k = 0, sum = 0;
    while(cin >> a){
        if(a == 0){
            cout << 1 << endl;
            return 0;
        }
        k++;
        sum += a;
    }

    sum += k-1;

    if(sum > m)     cout << "NA" << endl;
    else            cout << mc.nHk(k+1, m-sum) << endl;
    
    return 0;
}
0