結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー snukesnuke
提出日時 2016-07-08 22:45:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 3,719 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 78,224 KB
実行使用メモリ 14,056 KB
最終ジャッジ日時 2023-08-03 08:40:41
合計ジャッジ時間 4,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 13 ms
12,988 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 17 ms
13,576 KB
testcase_10 AC 5 ms
4,408 KB
testcase_11 AC 17 ms
14,056 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 17 ms
5,712 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 5 ms
4,632 KB
testcase_16 AC 10 ms
7,648 KB
testcase_17 AC 14 ms
10,280 KB
testcase_18 AC 28 ms
7,952 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,384 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,384 KB
testcase_43 AC 1 ms
4,384 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 25 ms
4,384 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 2 ms
4,384 KB
testcase_52 AC 5 ms
4,380 KB
testcase_53 AC 4 ms
4,380 KB
testcase_54 AC 7 ms
4,380 KB
testcase_55 AC 2 ms
4,384 KB
testcase_56 AC 3 ms
4,384 KB
testcase_57 AC 11 ms
4,380 KB
testcase_58 AC 20 ms
4,384 KB
testcase_59 AC 16 ms
4,384 KB
testcase_60 AC 8 ms
4,380 KB
testcase_61 AC 33 ms
4,384 KB
testcase_62 AC 8 ms
4,384 KB
testcase_63 AC 21 ms
4,384 KB
testcase_64 AC 7 ms
4,384 KB
testcase_65 AC 4 ms
4,380 KB
testcase_66 AC 7 ms
4,384 KB
testcase_67 AC 6 ms
4,380 KB
testcase_68 AC 7 ms
4,384 KB
testcase_69 AC 8 ms
8,496 KB
testcase_70 AC 5 ms
5,580 KB
testcase_71 AC 7 ms
7,088 KB
testcase_72 AC 4 ms
4,536 KB
testcase_73 AC 6 ms
6,028 KB
testcase_74 AC 7 ms
7,264 KB
testcase_75 AC 6 ms
6,652 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 10 ms
10,544 KB
testcase_78 AC 2 ms
4,380 KB
testcase_79 AC 2 ms
4,384 KB
testcase_80 AC 1 ms
4,384 KB
testcase_81 AC 2 ms
4,380 KB
testcase_82 AC 2 ms
4,384 KB
testcase_83 AC 2 ms
4,384 KB
testcase_84 AC 1 ms
4,380 KB
testcase_85 AC 2 ms
4,380 KB
testcase_86 AC 2 ms
4,384 KB
testcase_87 AC 2 ms
4,380 KB
testcase_88 AC 2 ms
4,384 KB
testcase_89 AC 12 ms
4,524 KB
testcase_90 AC 18 ms
5,924 KB
testcase_91 AC 31 ms
8,000 KB
testcase_92 AC 6 ms
4,380 KB
testcase_93 AC 20 ms
6,192 KB
testcase_94 AC 2 ms
4,380 KB
testcase_95 AC 21 ms
6,128 KB
testcase_96 AC 17 ms
5,600 KB
testcase_97 AC 15 ms
5,420 KB
testcase_98 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// Mod int
const int mod = 1000000007;
struct mint;
mint ex(mint a, ll tms);
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint& operator/=(const mint& a){ (x*=ex(a,mod-2).x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
mint ex(mint a, ll tms) {
  if(!tms) return 1;
  mint res = ex(a,tms/2);
  res *= res;
  return (tms&1)?res*a:res;
}
struct comb {
  vm f, g;
  comb(){}
  comb(int mx):f(mx+1),g(mx+1) {
    f[0] = 1;
    rrep(i,mx) f[i] = f[i-1]*i;
    g[mx] = ex(f[mx],mod-2);
    for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
  }
  mint c(int a, int b) {
    if (a < b) return 0;
    return f[a]*g[b]*g[a-b];
  }
};
//

int main() {
  int n, m = 0;
  scanf("%d",&n);
  int a, x = 0;
  while (scanf("%d",&a) == 1) {
    ++m;
    n -= a+1;
    x |= !a;
  }
  if (x) {
    cout<<1<<endl;
    return 0;
  }
  n++;
  if (n < 0) {
    cout<<"NA"<<endl;
    return 0;
  }
  comb c(n+m+10);
  mint ans = c.c(n+m,m);
  cout<<ans<<endl;
  return 0;
}





0