結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー n_vipn_vip
提出日時 2016-07-08 22:42:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 2,394 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 98,584 KB
実行使用メモリ 55,124 KB
最終ジャッジ日時 2024-04-21 07:25:27
合計ジャッジ時間 16,431 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
52,864 KB
testcase_01 AC 119 ms
52,736 KB
testcase_02 AC 119 ms
52,864 KB
testcase_03 AC 126 ms
52,992 KB
testcase_04 AC 130 ms
52,864 KB
testcase_05 AC 133 ms
52,992 KB
testcase_06 AC 141 ms
52,736 KB
testcase_07 AC 129 ms
52,864 KB
testcase_08 AC 121 ms
52,864 KB
testcase_09 AC 119 ms
53,120 KB
testcase_10 AC 124 ms
53,120 KB
testcase_11 AC 130 ms
53,248 KB
testcase_12 AC 128 ms
53,120 KB
testcase_13 AC 138 ms
54,228 KB
testcase_14 AC 129 ms
53,248 KB
testcase_15 AC 124 ms
53,120 KB
testcase_16 AC 127 ms
53,120 KB
testcase_17 AC 127 ms
53,376 KB
testcase_18 AC 145 ms
54,996 KB
testcase_19 AC 128 ms
52,864 KB
testcase_20 AC 129 ms
52,864 KB
testcase_21 AC 129 ms
52,864 KB
testcase_22 AC 130 ms
52,864 KB
testcase_23 AC 125 ms
52,992 KB
testcase_24 AC 127 ms
52,864 KB
testcase_25 AC 120 ms
52,864 KB
testcase_26 AC 129 ms
52,864 KB
testcase_27 AC 130 ms
52,864 KB
testcase_28 AC 120 ms
52,864 KB
testcase_29 AC 120 ms
52,864 KB
testcase_30 AC 124 ms
52,736 KB
testcase_31 AC 123 ms
52,864 KB
testcase_32 AC 126 ms
52,864 KB
testcase_33 AC 133 ms
52,992 KB
testcase_34 AC 126 ms
52,864 KB
testcase_35 AC 122 ms
52,864 KB
testcase_36 AC 120 ms
52,864 KB
testcase_37 AC 122 ms
52,864 KB
testcase_38 AC 131 ms
52,992 KB
testcase_39 AC 129 ms
52,864 KB
testcase_40 AC 133 ms
52,864 KB
testcase_41 AC 127 ms
52,864 KB
testcase_42 AC 120 ms
52,864 KB
testcase_43 AC 128 ms
52,864 KB
testcase_44 AC 125 ms
52,864 KB
testcase_45 AC 134 ms
52,992 KB
testcase_46 AC 128 ms
52,992 KB
testcase_47 AC 132 ms
52,864 KB
testcase_48 AC 137 ms
52,992 KB
testcase_49 AC 161 ms
55,124 KB
testcase_50 AC 133 ms
53,120 KB
testcase_51 AC 133 ms
52,992 KB
testcase_52 AC 132 ms
53,376 KB
testcase_53 AC 135 ms
53,120 KB
testcase_54 AC 130 ms
53,248 KB
testcase_55 AC 131 ms
52,864 KB
testcase_56 AC 131 ms
53,120 KB
testcase_57 AC 137 ms
54,096 KB
testcase_58 AC 150 ms
54,996 KB
testcase_59 AC 139 ms
54,100 KB
testcase_60 AC 134 ms
53,632 KB
testcase_61 AC 165 ms
55,120 KB
testcase_62 AC 134 ms
53,504 KB
testcase_63 AC 145 ms
55,124 KB
testcase_64 AC 127 ms
53,248 KB
testcase_65 AC 124 ms
53,248 KB
testcase_66 AC 133 ms
53,504 KB
testcase_67 AC 135 ms
53,632 KB
testcase_68 AC 138 ms
53,376 KB
testcase_69 AC 127 ms
52,864 KB
testcase_70 AC 122 ms
52,992 KB
testcase_71 AC 128 ms
52,864 KB
testcase_72 AC 128 ms
52,864 KB
testcase_73 AC 129 ms
52,864 KB
testcase_74 AC 127 ms
52,864 KB
testcase_75 AC 130 ms
52,864 KB
testcase_76 AC 124 ms
52,864 KB
testcase_77 AC 129 ms
52,864 KB
testcase_78 AC 128 ms
52,864 KB
testcase_79 AC 130 ms
52,736 KB
testcase_80 AC 127 ms
52,864 KB
testcase_81 AC 134 ms
52,864 KB
testcase_82 AC 136 ms
52,864 KB
testcase_83 AC 124 ms
52,864 KB
testcase_84 AC 124 ms
52,864 KB
testcase_85 AC 129 ms
52,864 KB
testcase_86 AC 125 ms
52,864 KB
testcase_87 AC 125 ms
52,992 KB
testcase_88 AC 122 ms
52,864 KB
testcase_89 AC 139 ms
53,376 KB
testcase_90 AC 133 ms
53,976 KB
testcase_91 AC 143 ms
55,124 KB
testcase_92 AC 126 ms
53,248 KB
testcase_93 AC 132 ms
54,224 KB
testcase_94 AC 127 ms
52,864 KB
testcase_95 AC 141 ms
54,100 KB
testcase_96 AC 140 ms
54,224 KB
testcase_97 AC 138 ms
54,228 KB
testcase_98 AC 128 ms
53,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
vector<ll> fact,finv,inv;
ll comb(ll n,ll r){
  if(n<r||r<0)return 0;
  return fact[n]*finv[n-r]%MOD*finv[r]%MOD;
}
class Doralion{
  void Modinvs(vector<ll> &re,int n){
    re.resize(n+1); re[1]=1;
    for(int i=2;i<=n;++i)re[i]=re[MOD%i]*(MOD-MOD/i)%MOD;
  }
  void Facts(vector<ll> &re,int n){
    re.resize(n+1); re[0]=1;
    rep(i,n)re[i+1]=re[i]*(i+1)%MOD;
  }
  void Factinvs(vector<ll> &re,const vector<ll> &inv,int n){
    re.resize(n+1); re[0]=1;
    rep(i,n)re[i+1]=re[i]*inv[i+1]%MOD;
  }
public:
  Doralion(int n){
    Modinvs(inv,n);
    Facts(fact,n);
    Factinvs(finv,inv,n);
  }
} doralion(2123456);

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int m;
  cin>>m;
  vector<int> a;
  int x;
  while(cin>>x) a.pb(x);
  if(a[0]==0){
    cout<<1<<endl;
    return 0;
  }
  int n=a.size();
  int s=accumulate(all(a),-n);
  m-=s;
  if(m<n*2-1){
    cout<<"NA"<<endl;
    return 0;
  }
  cout<<comb(m-n+1,n)<<endl;
  return 0;
}
0