結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー IL_mstaIL_msta
提出日時 2017-01-29 12:34:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 2,285 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 102,048 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 14:36:01
合計ジャッジ時間 4,488 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////
const ULL mod = 1000000007;
ULL inv[1000010];
ULL invMod(ULL k){//k**(mod-2)
//  098765432109876543210987654321
//0b111011100110101100101000000111
	ULL p = mod-2;
	ULL ret = 1;
	while(p){//30回回る
		if( p & 1 ){
			ret = (ret*k)%mod;
		}
		k = (k*k)%mod;
		p >>= 1;
	}
	return ret;
}

ULL nCk(ULL N,ULL k){
	k = min(k,N-k);
	if( k == 0 ){return 1;}
	if( k == 1 ){return N%mod;}

	//コピー
	//↓これで逆元の計算ができる! すごい!
	vector<ULL> INV(k+1);
	{
		INV[1] = 1;//1の(mod)逆元は1
		for(int i=2;i<=k;++i){
			INV[i] = (INV[mod%i] * (mod-mod/i))%mod;
		}
	}
	//

	ULL ret = 1;
	for(int i=1;i<=k;++i){
		ret *= ((N+1-i)*INV[i])%mod;//OVF
		ret %= mod;
	}
	/*
	ULL kkai = 1;
	for(int i=1;i<=k;++i){
		kkai *= i;
		kkai %= mod;
	}
	ret = ( ret*invMod(kkai) ) %mod;
	*/
	
	return ret;
}

inline void solve(){
	int N;
	scanf("%d",&N);
	int temp	= 0;
	int sum		= 0;
	int kind	= 0;

	while( scanf("%d",&temp) != EOF ){
		sum += temp;
		++kind;
	}
	if( sum == 0 ){
		printf("1\n");
		return;
	}
	if( sum + kind-1 > N ){
		printf("NA\n");
		return;
	}
	int aki = N - (sum+kind-1);
	printf("%d\n", nCk(aki+kind,kind) );
}

int main(void){
	//std::cin.tie(0);
	//std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数をいっぱい表示する。16?

	solve();

	return 0;
}
0