結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー zaichuzaichu
提出日時 2016-07-09 18:59:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 2,180 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 89,088 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-21 10:47:55
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 16 ms
8,192 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 10 ms
6,144 KB
testcase_07 AC 22 ms
10,496 KB
testcase_08 AC 11 ms
6,272 KB
testcase_09 AC 20 ms
9,344 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 21 ms
9,344 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 31 ms
10,496 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 11 ms
5,760 KB
testcase_17 AC 20 ms
7,424 KB
testcase_18 AC 31 ms
8,064 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 32 ms
8,448 KB
testcase_50 AC 6 ms
5,376 KB
testcase_51 AC 5 ms
5,376 KB
testcase_52 AC 21 ms
9,088 KB
testcase_53 AC 7 ms
5,376 KB
testcase_54 AC 26 ms
10,368 KB
testcase_55 AC 6 ms
5,376 KB
testcase_56 AC 3 ms
5,376 KB
testcase_57 AC 18 ms
6,656 KB
testcase_58 AC 33 ms
9,728 KB
testcase_59 AC 26 ms
8,320 KB
testcase_60 AC 11 ms
5,376 KB
testcase_61 AC 43 ms
10,112 KB
testcase_62 AC 17 ms
7,040 KB
testcase_63 AC 30 ms
8,320 KB
testcase_64 AC 23 ms
9,600 KB
testcase_65 AC 7 ms
5,376 KB
testcase_66 AC 10 ms
5,376 KB
testcase_67 AC 16 ms
7,040 KB
testcase_68 AC 25 ms
10,112 KB
testcase_69 AC 16 ms
8,448 KB
testcase_70 AC 13 ms
7,040 KB
testcase_71 AC 8 ms
5,376 KB
testcase_72 AC 20 ms
9,600 KB
testcase_73 AC 9 ms
5,632 KB
testcase_74 AC 8 ms
5,504 KB
testcase_75 AC 8 ms
5,632 KB
testcase_76 AC 12 ms
6,784 KB
testcase_77 AC 12 ms
6,784 KB
testcase_78 AC 5 ms
5,376 KB
testcase_79 AC 7 ms
5,376 KB
testcase_80 AC 5 ms
5,376 KB
testcase_81 AC 2 ms
5,376 KB
testcase_82 AC 18 ms
9,216 KB
testcase_83 AC 10 ms
6,016 KB
testcase_84 AC 5 ms
5,376 KB
testcase_85 AC 21 ms
9,984 KB
testcase_86 AC 18 ms
9,216 KB
testcase_87 AC 3 ms
5,376 KB
testcase_88 AC 2 ms
5,376 KB
testcase_89 AC 16 ms
6,400 KB
testcase_90 AC 32 ms
10,624 KB
testcase_91 AC 33 ms
8,576 KB
testcase_92 AC 8 ms
5,376 KB
testcase_93 AC 26 ms
8,192 KB
testcase_94 AC 15 ms
8,064 KB
testcase_95 AC 22 ms
6,656 KB
testcase_96 AC 31 ms
10,496 KB
testcase_97 AC 26 ms
9,344 KB
testcase_98 AC 22 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define GRESORT(v) sort(v.begin(),v.end(),greater<int>())
#define REVERSE(v) reverse(v.begin(),v.end())
#define overlap(v) v.erase(unique(v.begin(),v.end()),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF 999999999
#define mins(a,b) a = min(a,b);
#define maxs(a,b) a = max(a,b);

//4近傍
//int dy[]={0, 0, 1, -1};
//int dx[]={1, -1, 0, 0};

//8近傍
//int dy[]={0,0,1,-1,1,1,-1,-1};
//int dx[]={1,-1,0,0,1,-1,1,-1};

ll mod = 1000000007;
vector<ll> fact;

ll pow_mod(ll a,ll b){
    ll ret = 1;
    while(b > 0){
        if(b & 1){
            ret = ret * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}

ll comb(ll x,ll y){
    return fact[x] * pow_mod(fact[y] * fact[x-y] % mod,mod-2) % mod;
}

void solve(){
    int m; cin >> m;
    fact.resize(m);
    fact[0] = 1;
    fact[1] = 1;
    for(ll i = 2; i < m; i++){
        fact[i] = fact[i-1] * i % mod;
    }
    ll sum = 0, cnt = 0;
    ll val;
    while(cin >> val){
        if(val == -1) break;
        sum += val;
        cnt++;
    }
    if(sum + cnt - 1 > m){
        cout << "NA" << endl;
        return;
    }
    if(sum == 0){
        cout << 1 << endl;
        return;
    }

    ll ans = comb(m - sum + 1,cnt);
    ans = (ans+mod) % mod;
    cout << ans << endl;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    solve();

    return 0;
}
0