結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー btkbtk
提出日時 2016-07-08 22:40:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 165,112 KB
実行使用メモリ 15,900 KB
最終ジャッジ日時 2023-08-03 08:33:35
合計ジャッジ時間 6,459 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,612 KB
testcase_01 AC 13 ms
15,788 KB
testcase_02 AC 13 ms
15,636 KB
testcase_03 AC 13 ms
15,704 KB
testcase_04 AC 13 ms
15,688 KB
testcase_05 AC 13 ms
15,636 KB
testcase_06 AC 13 ms
15,644 KB
testcase_07 AC 13 ms
15,692 KB
testcase_08 AC 13 ms
15,776 KB
testcase_09 AC 15 ms
15,636 KB
testcase_10 AC 14 ms
15,632 KB
testcase_11 AC 16 ms
15,620 KB
testcase_12 AC 14 ms
15,636 KB
testcase_13 AC 22 ms
15,852 KB
testcase_14 AC 16 ms
15,692 KB
testcase_15 AC 14 ms
15,692 KB
testcase_16 AC 14 ms
15,612 KB
testcase_17 AC 16 ms
15,640 KB
testcase_18 AC 29 ms
15,688 KB
testcase_19 AC 13 ms
15,684 KB
testcase_20 AC 14 ms
15,700 KB
testcase_21 AC 13 ms
15,608 KB
testcase_22 AC 13 ms
15,628 KB
testcase_23 AC 13 ms
15,636 KB
testcase_24 AC 13 ms
15,692 KB
testcase_25 AC 13 ms
15,640 KB
testcase_26 AC 13 ms
15,704 KB
testcase_27 AC 13 ms
15,632 KB
testcase_28 AC 13 ms
15,704 KB
testcase_29 AC 13 ms
15,688 KB
testcase_30 AC 13 ms
15,700 KB
testcase_31 AC 13 ms
15,636 KB
testcase_32 AC 13 ms
15,756 KB
testcase_33 AC 13 ms
15,852 KB
testcase_34 AC 13 ms
15,644 KB
testcase_35 AC 13 ms
15,760 KB
testcase_36 AC 14 ms
15,628 KB
testcase_37 AC 13 ms
15,636 KB
testcase_38 AC 13 ms
15,684 KB
testcase_39 AC 13 ms
15,616 KB
testcase_40 AC 13 ms
15,608 KB
testcase_41 AC 14 ms
15,700 KB
testcase_42 AC 13 ms
15,752 KB
testcase_43 AC 13 ms
15,808 KB
testcase_44 AC 13 ms
15,684 KB
testcase_45 AC 13 ms
15,796 KB
testcase_46 AC 13 ms
15,640 KB
testcase_47 AC 13 ms
15,632 KB
testcase_48 AC 13 ms
15,684 KB
testcase_49 AC 30 ms
15,896 KB
testcase_50 AC 14 ms
15,744 KB
testcase_51 AC 14 ms
15,644 KB
testcase_52 AC 16 ms
15,628 KB
testcase_53 AC 15 ms
15,684 KB
testcase_54 AC 17 ms
15,632 KB
testcase_55 AC 13 ms
15,636 KB
testcase_56 AC 14 ms
15,700 KB
testcase_57 AC 20 ms
15,720 KB
testcase_58 AC 27 ms
15,724 KB
testcase_59 AC 24 ms
15,856 KB
testcase_60 AC 18 ms
15,684 KB
testcase_61 AC 37 ms
15,692 KB
testcase_62 AC 18 ms
15,788 KB
testcase_63 AC 28 ms
15,612 KB
testcase_64 AC 17 ms
15,760 KB
testcase_65 AC 15 ms
15,612 KB
testcase_66 AC 18 ms
15,896 KB
testcase_67 AC 17 ms
15,720 KB
testcase_68 AC 17 ms
15,632 KB
testcase_69 AC 14 ms
15,712 KB
testcase_70 AC 13 ms
15,628 KB
testcase_71 AC 13 ms
15,756 KB
testcase_72 AC 13 ms
15,752 KB
testcase_73 AC 13 ms
15,696 KB
testcase_74 AC 13 ms
15,620 KB
testcase_75 AC 13 ms
15,640 KB
testcase_76 AC 13 ms
15,612 KB
testcase_77 AC 13 ms
15,692 KB
testcase_78 AC 13 ms
15,700 KB
testcase_79 AC 13 ms
15,752 KB
testcase_80 AC 14 ms
15,740 KB
testcase_81 AC 13 ms
15,684 KB
testcase_82 AC 13 ms
15,612 KB
testcase_83 AC 13 ms
15,896 KB
testcase_84 AC 13 ms
15,700 KB
testcase_85 AC 13 ms
15,612 KB
testcase_86 AC 13 ms
15,632 KB
testcase_87 AC 13 ms
15,700 KB
testcase_88 AC 13 ms
15,784 KB
testcase_89 AC 19 ms
15,860 KB
testcase_90 AC 22 ms
15,624 KB
testcase_91 AC 30 ms
15,760 KB
testcase_92 AC 15 ms
15,636 KB
testcase_93 AC 23 ms
15,840 KB
testcase_94 AC 14 ms
15,884 KB
testcase_95 AC 24 ms
15,900 KB
testcase_96 AC 22 ms
15,620 KB
testcase_97 AC 21 ms
15,700 KB
testcase_98 AC 17 ms
15,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);cout<<fixed;cout<<setprecision(10);}}init;
#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(it,v) for(auto &it:v)
typedef long long LL;
const LL MOD=1e9+7;

LL fact[2000000];
struct init2{
    init2(){
	fact[0]=1;
	rep(i,1500000)fact[i+1]=fact[i]*(i+1)%MOD;
    }
}i2;
// a x + b y = gcd(a, b)
// O(log (a+b) )
LL extgcd(LL a, LL b, LL &x, LL &y) {
  LL g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

// mを法とするaの逆元
// O(log a)
LL invMod(LL a) {
	LL x, y;
	if (extgcd(a, MOD, x, y) == 1)return (x + MOD) % MOD;
	else	 return 0; // unsolvable
}


LL Comb(LL n,LL k){
	LL u=fact[n];
	LL d=(fact[k]*fact[n-k])%MOD;
	return (u*invMod(d))%MOD;
}

int main(){
    LL M,rest;
    cin>>M;
    rest=M;
    int N=0;
    for(int num;cin>>num;N++){
	rest-=num;
    }
    if(rest==M)cout<<1<<endl;
    else{
	if(rest<N-1){
	    cout<<"NA"<<endl;
	}
	else{
	    rest-=N-1;
	    cout<<Comb(N+rest,N)<<endl;
	}
    }
    
    return 0;
}
0