結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー rickythetarickytheta
提出日時 2016-07-08 22:28:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 144,200 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2023-08-03 06:50:03
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
13,756 KB
testcase_01 AC 2 ms
5,456 KB
testcase_02 AC 11 ms
13,876 KB
testcase_03 AC 2 ms
5,628 KB
testcase_04 AC 11 ms
13,988 KB
testcase_05 AC 2 ms
5,452 KB
testcase_06 AC 2 ms
5,480 KB
testcase_07 AC 2 ms
5,544 KB
testcase_08 AC 2 ms
5,472 KB
testcase_09 AC 14 ms
13,944 KB
testcase_10 AC 14 ms
13,764 KB
testcase_11 AC 15 ms
13,684 KB
testcase_12 AC 13 ms
13,724 KB
testcase_13 AC 23 ms
15,824 KB
testcase_14 AC 15 ms
13,852 KB
testcase_15 AC 12 ms
13,976 KB
testcase_16 AC 13 ms
13,724 KB
testcase_17 AC 15 ms
13,976 KB
testcase_18 AC 34 ms
15,800 KB
testcase_19 AC 11 ms
13,692 KB
testcase_20 AC 11 ms
13,736 KB
testcase_21 AC 11 ms
13,796 KB
testcase_22 AC 11 ms
13,812 KB
testcase_23 AC 12 ms
13,812 KB
testcase_24 AC 11 ms
13,796 KB
testcase_25 AC 12 ms
13,816 KB
testcase_26 AC 11 ms
13,684 KB
testcase_27 AC 11 ms
13,688 KB
testcase_28 AC 11 ms
13,740 KB
testcase_29 AC 11 ms
13,720 KB
testcase_30 AC 12 ms
13,820 KB
testcase_31 AC 11 ms
13,684 KB
testcase_32 AC 12 ms
13,788 KB
testcase_33 AC 11 ms
13,692 KB
testcase_34 AC 11 ms
13,724 KB
testcase_35 AC 12 ms
13,796 KB
testcase_36 AC 12 ms
13,856 KB
testcase_37 AC 11 ms
13,792 KB
testcase_38 AC 12 ms
13,684 KB
testcase_39 AC 11 ms
13,804 KB
testcase_40 AC 11 ms
13,684 KB
testcase_41 AC 11 ms
13,684 KB
testcase_42 AC 12 ms
13,744 KB
testcase_43 AC 12 ms
13,732 KB
testcase_44 AC 11 ms
13,776 KB
testcase_45 AC 11 ms
13,772 KB
testcase_46 AC 12 ms
13,696 KB
testcase_47 AC 11 ms
13,764 KB
testcase_48 AC 11 ms
13,692 KB
testcase_49 AC 26 ms
7,596 KB
testcase_50 AC 3 ms
5,436 KB
testcase_51 AC 3 ms
5,608 KB
testcase_52 AC 6 ms
5,476 KB
testcase_53 AC 4 ms
5,524 KB
testcase_54 AC 7 ms
5,540 KB
testcase_55 AC 2 ms
5,724 KB
testcase_56 AC 4 ms
5,448 KB
testcase_57 AC 12 ms
7,612 KB
testcase_58 AC 21 ms
7,528 KB
testcase_59 AC 17 ms
7,596 KB
testcase_60 AC 9 ms
5,440 KB
testcase_61 AC 35 ms
7,496 KB
testcase_62 AC 9 ms
5,536 KB
testcase_63 AC 23 ms
7,772 KB
testcase_64 AC 7 ms
5,432 KB
testcase_65 AC 5 ms
5,608 KB
testcase_66 AC 8 ms
5,488 KB
testcase_67 AC 8 ms
5,472 KB
testcase_68 AC 7 ms
5,444 KB
testcase_69 AC 11 ms
13,812 KB
testcase_70 AC 11 ms
13,752 KB
testcase_71 AC 11 ms
13,764 KB
testcase_72 AC 12 ms
13,820 KB
testcase_73 AC 11 ms
13,748 KB
testcase_74 AC 12 ms
13,756 KB
testcase_75 AC 12 ms
13,768 KB
testcase_76 AC 11 ms
13,744 KB
testcase_77 AC 11 ms
13,732 KB
testcase_78 AC 11 ms
13,816 KB
testcase_79 AC 11 ms
13,764 KB
testcase_80 AC 12 ms
13,720 KB
testcase_81 AC 12 ms
13,724 KB
testcase_82 AC 11 ms
13,688 KB
testcase_83 AC 11 ms
13,692 KB
testcase_84 AC 12 ms
13,772 KB
testcase_85 AC 11 ms
13,688 KB
testcase_86 AC 11 ms
13,768 KB
testcase_87 AC 12 ms
13,756 KB
testcase_88 AC 11 ms
13,684 KB
testcase_89 AC 19 ms
13,972 KB
testcase_90 AC 25 ms
15,796 KB
testcase_91 AC 34 ms
15,792 KB
testcase_92 AC 15 ms
13,680 KB
testcase_93 AC 26 ms
15,796 KB
testcase_94 AC 12 ms
13,752 KB
testcase_95 AC 27 ms
15,744 KB
testcase_96 AC 23 ms
15,872 KB
testcase_97 AC 23 ms
15,772 KB
testcase_98 AC 17 ms
13,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int m;
int k;
int h[1252525];

ll fact[1252525];
void init(){
  fact[0] = 1;
  FOR(i,1,1252525){
    fact[i] = i*fact[i-1]%MOD;
  }
}

ll inv(ll x){
  ll k = MOD-2;
  ll ret = 1;
  while(k){
    if(k&1)ret=ret*x%MOD;
    x=x*x%MOD;
    k>>=1;
  }
  return ret;
}

int comb(int a,int b){
  ll ret = 1;
  init();
  ret *= fact[a];
  ret %= MOD;
  ret *= inv(fact[b]);
  ret %= MOD;
  ret *= inv(fact[a-b]);
  ret %= MOD;
  return (int)ret;
}

int main(){
  scanf("%d",&m);
  k=0;
  while(~scanf("%d",&h[k++]));
  --k;
  if(h[0]==0){
    puts("1");
    return 0;
  }
  int sum = 0;
  REP(i,k)sum += h[i];
  m -= sum;
  if(m+1<k){
    puts("NA");
    return 0;
  }
  // ans = m+1 C k
  printf("%d\n",comb(m+1,k));
  return 0;
}
0