結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー h_noson
提出日時 2016-07-08 22:55:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 64,984 KB
実行使用メモリ 13,212 KB
最終ジャッジ日時 2024-10-13 06:20:43
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 99
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |     scanf("%d",&m);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

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

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)

const int INF = 1e8;
const int MOD = 1e9+7;

typedef long long ll;

int h[500000];
ll frac[1000001];

int modinv(ll x) {
    int n = MOD-2;
    ll ret = 1;
    while (n) {
        if (n%2) {
            ret *= x;
            ret %= MOD;
        }
        x *= x;
        x %= MOD;
        n /= 2;
    }
    return ret;
}

int main(void) {
    int i, m, n;
    scanf("%d",&m);
    n = 0;
    while (scanf("%d",&h[n++]) != EOF);
    n--;

    frac[0] = 1;
    rep (i,1000000) frac[i+1] = frac[i] * (i+1) % MOD;

    m -= n - 1;
    rep (i,n) if (h[i] > 0)
        m -= h[i] - 1;
    int ans;
    if (m < n) {
        cout << "NA" << endl;
        return 0;
    }
    if (h[0] != 0)
        ans = frac[m] * modinv(frac[n]) % MOD * modinv(frac[m-n]) % MOD;
    else
        ans = 1;
    cout << ans << endl;
    return 0;
}
0