結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー koyoprokoyopro
提出日時 2020-02-16 00:11:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,756 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 161,468 KB
実行使用メモリ 29,296 KB
最終ジャッジ日時 2024-04-16 03:22:24
合計ジャッジ時間 10,532 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
29,164 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 64 ms
29,144 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 69 ms
29,080 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 69 ms
29,096 KB
testcase_10 AC 67 ms
29,116 KB
testcase_11 AC 68 ms
29,172 KB
testcase_12 AC 64 ms
28,992 KB
testcase_13 AC 77 ms
29,112 KB
testcase_14 AC 64 ms
29,148 KB
testcase_15 AC 69 ms
29,248 KB
testcase_16 AC 68 ms
29,132 KB
testcase_17 AC 66 ms
29,096 KB
testcase_18 AC 83 ms
29,096 KB
testcase_19 AC 66 ms
29,188 KB
testcase_20 AC 64 ms
29,256 KB
testcase_21 AC 66 ms
29,092 KB
testcase_22 AC 65 ms
29,076 KB
testcase_23 AC 63 ms
29,160 KB
testcase_24 AC 65 ms
29,132 KB
testcase_25 AC 68 ms
29,088 KB
testcase_26 AC 63 ms
29,124 KB
testcase_27 AC 70 ms
29,168 KB
testcase_28 AC 66 ms
29,168 KB
testcase_29 AC 66 ms
29,132 KB
testcase_30 AC 66 ms
29,296 KB
testcase_31 AC 66 ms
29,176 KB
testcase_32 AC 67 ms
28,988 KB
testcase_33 AC 65 ms
29,088 KB
testcase_34 AC 64 ms
29,116 KB
testcase_35 AC 63 ms
29,144 KB
testcase_36 AC 59 ms
29,144 KB
testcase_37 AC 61 ms
29,100 KB
testcase_38 AC 60 ms
29,080 KB
testcase_39 AC 67 ms
29,284 KB
testcase_40 AC 63 ms
29,116 KB
testcase_41 AC 64 ms
29,120 KB
testcase_42 AC 64 ms
28,976 KB
testcase_43 AC 64 ms
29,124 KB
testcase_44 AC 63 ms
29,072 KB
testcase_45 AC 64 ms
29,092 KB
testcase_46 AC 64 ms
29,108 KB
testcase_47 AC 64 ms
29,096 KB
testcase_48 AC 62 ms
29,092 KB
testcase_49 AC 20 ms
6,940 KB
testcase_50 AC 3 ms
6,944 KB
testcase_51 AC 3 ms
6,940 KB
testcase_52 AC 5 ms
6,940 KB
testcase_53 AC 4 ms
6,944 KB
testcase_54 AC 6 ms
6,940 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 3 ms
6,944 KB
testcase_57 AC 10 ms
6,944 KB
testcase_58 AC 16 ms
6,944 KB
testcase_59 AC 14 ms
6,940 KB
testcase_60 AC 7 ms
6,944 KB
testcase_61 AC 26 ms
6,940 KB
testcase_62 AC 7 ms
6,944 KB
testcase_63 AC 17 ms
6,944 KB
testcase_64 AC 6 ms
6,944 KB
testcase_65 AC 4 ms
6,944 KB
testcase_66 AC 6 ms
6,944 KB
testcase_67 AC 7 ms
6,940 KB
testcase_68 AC 6 ms
6,940 KB
testcase_69 AC 66 ms
29,080 KB
testcase_70 AC 64 ms
29,196 KB
testcase_71 AC 63 ms
29,140 KB
testcase_72 AC 63 ms
29,104 KB
testcase_73 AC 67 ms
29,104 KB
testcase_74 AC 63 ms
29,020 KB
testcase_75 AC 66 ms
29,128 KB
testcase_76 AC 71 ms
29,096 KB
testcase_77 AC 69 ms
29,120 KB
testcase_78 AC 62 ms
29,084 KB
testcase_79 AC 66 ms
29,096 KB
testcase_80 AC 64 ms
29,200 KB
testcase_81 AC 68 ms
29,088 KB
testcase_82 AC 66 ms
29,148 KB
testcase_83 AC 65 ms
29,088 KB
testcase_84 AC 64 ms
29,000 KB
testcase_85 AC 66 ms
29,160 KB
testcase_86 AC 67 ms
29,176 KB
testcase_87 AC 67 ms
29,176 KB
testcase_88 AC 64 ms
29,084 KB
testcase_89 AC 72 ms
29,124 KB
testcase_90 AC 70 ms
29,124 KB
testcase_91 AC 86 ms
29,164 KB
testcase_92 AC 69 ms
29,124 KB
testcase_93 AC 75 ms
29,144 KB
testcase_94 AC 67 ms
28,996 KB
testcase_95 AC 75 ms
29,164 KB
testcase_96 AC 76 ms
29,152 KB
testcase_97 AC 72 ms
28,968 KB
testcase_98 AC 69 ms
29,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int M;
vector<int> H;

const int MAX = 1100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if (!fac[n]) COMinit();
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
    cin>>M;
    int r = M; // 残った余白
    int h, cnt = 0;
    while(cin>>h) {
        cnt++;
        r -= h;
    }
    if (r==M) {
        cout << 1 << endl;
        return;
    }
    r -= (cnt - 1);
    if (r<0) {
        cout << "NA" << endl;
        return;
    }
    cout << COM(r + cnt, r) << endl;
}
0