結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー IL_mstaIL_msta
提出日時 2017-01-29 10:53:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,501 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 106,532 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 14:32:05
合計ジャッジ時間 5,269 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 17 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 17 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 4 ms
4,376 KB
testcase_53 AC 3 ms
4,376 KB
testcase_54 AC 5 ms
4,376 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 7 ms
4,380 KB
testcase_58 AC 15 ms
4,376 KB
testcase_59 AC 11 ms
4,380 KB
testcase_60 AC 6 ms
4,380 KB
testcase_61 AC 22 ms
4,376 KB
testcase_62 AC 6 ms
4,376 KB
testcase_63 AC 14 ms
4,376 KB
testcase_64 AC 5 ms
4,380 KB
testcase_65 AC 3 ms
4,384 KB
testcase_66 AC 5 ms
4,376 KB
testcase_67 AC 4 ms
4,380 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 1 ms
4,376 KB
testcase_70 AC 1 ms
4,380 KB
testcase_71 AC 1 ms
4,380 KB
testcase_72 AC 1 ms
4,376 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 1 ms
4,376 KB
testcase_75 AC 1 ms
4,376 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 1 ms
4,380 KB
testcase_78 AC 1 ms
4,376 KB
testcase_79 AC 1 ms
4,380 KB
testcase_80 AC 1 ms
4,380 KB
testcase_81 AC 2 ms
4,376 KB
testcase_82 AC 1 ms
4,380 KB
testcase_83 AC 1 ms
4,376 KB
testcase_84 AC 1 ms
4,376 KB
testcase_85 AC 1 ms
4,376 KB
testcase_86 AC 1 ms
4,376 KB
testcase_87 AC 2 ms
4,376 KB
testcase_88 AC 1 ms
4,376 KB
testcase_89 AC 6 ms
4,376 KB
testcase_90 AC 9 ms
4,380 KB
testcase_91 AC 16 ms
4,380 KB
testcase_92 AC 4 ms
4,380 KB
testcase_93 AC 12 ms
4,380 KB
testcase_94 AC 1 ms
4,380 KB
testcase_95 AC 11 ms
4,380 KB
testcase_96 AC 10 ms
4,376 KB
testcase_97 AC 8 ms
4,380 KB
testcase_98 AC 5 ms
4,380 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 NCK[1000001][1000001];
ULL nCk(ULL N,ULL k){
	k = min(k,N-k);
	if( k== 0 ){return 1;}
	if( k==1 ){return N%mod;}
	if( NCK[N][k] ){return NCK[N][k];}
	NCK[N][k] = (nCk(N-1,k-1) + nCk(N-1,k))%mod;
	return NCK[N][k];
}*/
ULL invMod(ULL k,ULL p){//k**(mod-2)
	//k^p
	vector<ULL> kPow2;
	ULL A = k;
	kPow2.push_back(k%mod);//k**1
	for(ULL i=2;i<=p;i*=2){
		A = (A*A)%mod;
		kPow2.push_back(A);
	}
	ULL ret=1;
	ULL temp = p;
	ULL turn=0;//
	while(temp){
		if( temp & 1 ){
			ret = (ret*kPow2[turn])%mod;
		}
		temp >>= 1;
		++turn;
	}
	return ret;
}

ULL nCk(ULL N,ULL k){
	k = min(k,N-k);
	if( k == 0 ){return 1;}
	if( k == 1 ){return N%mod;}
	ULL ret = 1;
	for(int i=1;i<=k;++i){
		ret *= ((N+1-i)*invMod(i,mod-2))%mod;//OVF
		ret %= mod;
	}
	return ret;
}

inline void solve(){
	int N;
	cin >> N;
	int temp= 0;
	int sum = 0;
	int kind = 0;

	while(1){
		cin >> temp;
		if( cin.eof() ){break;}
		sum += temp;
		++kind;
	}
	if( sum == 0 ){
		cout << 1 << endl;
		return;
	}
	if( sum + kind-1 > N ){
		cout << "NA" << endl;
		return;
	}
	int aki = N - (sum+kind-1);
	/*
	aki 移動可能な空きます
	kind+1	入れる事の出来る場所
	----
	aki個のブロックをkind+1個に分割
	AAAAA
	仕切りの数はkind個
	akiの数+1の中からkind個選ぶ
	(aki+1)Hkind
	(aki+1+kind-1)Ckind
	*/
	cout << nCk(aki+kind,kind) << endl;
}

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