結果
| 問題 | No.389 ロジックパズルの組み合わせ | 
| コンテスト | |
| ユーザー |  a | 
| 提出日時 | 2016-07-08 23:23:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 44 ms / 2,000 ms | 
| コード長 | 925 bytes | 
| コンパイル時間 | 565 ms | 
| コンパイル使用メモリ | 69,128 KB | 
| 実行使用メモリ | 7,456 KB | 
| 最終ジャッジ日時 | 2024-10-13 07:08:00 | 
| 合計ジャッジ時間 | 3,442 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 99 | 
ソースコード
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int m;
int h[1111111], s=0;
ll modpow(ll a, ll b) {
  if (b == 0) return 1;
  ll ret = modpow(a*a%mod, b/2);
  if (b%2 == 1) ret = (ret*a)%mod;
  return ret;
}
ll C(ll n, ll k) {
  ll p = 1, q = 1;
  for (int i = n; i >= 1; i--) p = (p*i)%mod;
  for (int i = k; i >= 1; i--) q = (q*i)%mod;
  for (int i = n-k; i >= 1; i--) q = (q*i)%mod;
  return (p * modpow(q, mod-2))%mod;
}
int main(void) {
  cin >> m;
  string buf;
  getchar();
  getline(cin, buf);
  stringstream ss(buf);
  int a;
  int sum = 0;
  while (ss >> a) {
    h[s++] = a;
    sum += a;
    if (s > 1) sum += 1;
  }
  m -= sum;
  if (m < 0) {
    puts("NA");
  } else if (h[0] == 0) {
    puts("1");
  } else {
    // printf("%d %d %d\n", s, sum, m);
    printf("%lld\n", C(s+1+m-1, m));
  }
}
            
            
            
        