結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー parukiparuki
提出日時 2016-07-08 22:35:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 2,914 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 166,004 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:01:50
合計ジャッジ時間 5,889 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 150 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 157 ms
6,944 KB
testcase_10 AC 21 ms
6,944 KB
testcase_11 AC 161 ms
6,940 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 52 ms
6,944 KB
testcase_14 AC 20 ms
6,940 KB
testcase_15 AC 24 ms
6,944 KB
testcase_16 AC 70 ms
6,944 KB
testcase_17 AC 105 ms
6,944 KB
testcase_18 AC 91 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,948 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 1 ms
6,944 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 1 ms
6,944 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 30 ms
6,944 KB
testcase_50 AC 3 ms
6,940 KB
testcase_51 AC 3 ms
6,940 KB
testcase_52 AC 6 ms
6,944 KB
testcase_53 AC 4 ms
6,944 KB
testcase_54 AC 8 ms
6,944 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 4 ms
6,944 KB
testcase_57 AC 14 ms
6,940 KB
testcase_58 AC 26 ms
6,940 KB
testcase_59 AC 19 ms
6,940 KB
testcase_60 AC 10 ms
6,944 KB
testcase_61 AC 39 ms
6,940 KB
testcase_62 AC 10 ms
6,944 KB
testcase_63 AC 26 ms
6,944 KB
testcase_64 AC 8 ms
6,940 KB
testcase_65 AC 5 ms
6,944 KB
testcase_66 AC 9 ms
6,940 KB
testcase_67 AC 9 ms
6,944 KB
testcase_68 AC 8 ms
6,944 KB
testcase_69 AC 76 ms
6,940 KB
testcase_70 AC 34 ms
6,944 KB
testcase_71 AC 56 ms
6,944 KB
testcase_72 AC 23 ms
6,944 KB
testcase_73 AC 41 ms
6,940 KB
testcase_74 AC 58 ms
6,940 KB
testcase_75 AC 51 ms
6,944 KB
testcase_76 AC 19 ms
6,944 KB
testcase_77 AC 108 ms
6,940 KB
testcase_78 AC 6 ms
6,940 KB
testcase_79 AC 1 ms
6,940 KB
testcase_80 AC 2 ms
6,948 KB
testcase_81 AC 2 ms
6,940 KB
testcase_82 AC 2 ms
6,944 KB
testcase_83 AC 2 ms
6,940 KB
testcase_84 AC 2 ms
6,940 KB
testcase_85 AC 1 ms
6,940 KB
testcase_86 AC 2 ms
6,940 KB
testcase_87 AC 2 ms
6,940 KB
testcase_88 AC 2 ms
6,940 KB
testcase_89 AC 33 ms
6,940 KB
testcase_90 AC 57 ms
6,944 KB
testcase_91 AC 100 ms
6,944 KB
testcase_92 AC 15 ms
6,940 KB
testcase_93 AC 63 ms
6,944 KB
testcase_94 AC 2 ms
6,944 KB
testcase_95 AC 63 ms
6,940 KB
testcase_96 AC 48 ms
6,940 KB
testcase_97 AC 45 ms
6,944 KB
testcase_98 AC 21 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt{
public:
    ModInt():value(0){}
    ModInt(int val):value(val<0?MOD+val%MOD:val%MOD){ }
    
    ModInt& operator+=(ModInt that){
        value = value+that.value;
        if(value>=MOD)value-=MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that){
        value -= that.value;
        if(value<0)value+=MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that){
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that){
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const{
        return ModInt(*this)+=that;
    }
    ModInt operator-(ModInt that) const{
        return ModInt(*this)-=that;
    }
    ModInt operator*(ModInt that) const{
        return ModInt(*this)*=that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt operator^(long long k) const{
        ModInt n = *this, res = 1;
        while(k){
            if(k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, 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);
    }
    int toi() const{ return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x){
    os << x.toi();
    return os;
}

/*
n個のものからr個選ぶ場合の数
O(n+r)
*/
mint nCr(int n, int r){
    mint res = 1;
    for(int i = 2; i <= n; ++i)
        res *= i;
    for(int i = 2; i <= n - r; ++i)
        res /= i;
    for(int i = 2; i <= r; ++i)
        res /= i;
    return res;
}

/*
n個のものから「重複を許して」r個選ぶ場合の数
O(n+r)
*/
mint nHr(int n, int r){
    return nCr(n + r - 1, r);
}

int main(){
    int N;
    cin >> N;
    vi a;
    int x;
    while(~scanf("%d", &x)){
        a.push_back(x);
    }
    if(sz(a) == 1 && (a[0] == 0 || a[0] == N)){
        puts("1");
        return 0;
    }

    int sum = -1;
    each(y, a){
        sum += y + 1;
        if(sum > N){
            puts("NA");
            return 0;
        }
    }

    mint ans = nHr(sz(a) + 1, N - sum);
    cout << ans << endl;
}
0