結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 👑 kmjpkmjp
提出日時 2016-07-08 22:25:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 148,380 KB
実行使用メモリ 29,136 KB
最終ジャッジ日時 2023-08-03 06:45:49
合計ジャッジ時間 9,052 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
26,848 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 62 ms
26,772 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 62 ms
26,768 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 65 ms
26,944 KB
testcase_10 AC 62 ms
27,060 KB
testcase_11 AC 64 ms
26,892 KB
testcase_12 AC 62 ms
26,896 KB
testcase_13 AC 72 ms
27,896 KB
testcase_14 AC 64 ms
27,108 KB
testcase_15 AC 68 ms
26,896 KB
testcase_16 AC 63 ms
26,900 KB
testcase_17 AC 63 ms
27,084 KB
testcase_18 AC 81 ms
29,136 KB
testcase_19 AC 59 ms
26,804 KB
testcase_20 AC 61 ms
26,840 KB
testcase_21 AC 62 ms
26,764 KB
testcase_22 AC 61 ms
26,800 KB
testcase_23 AC 59 ms
26,784 KB
testcase_24 AC 61 ms
26,764 KB
testcase_25 AC 60 ms
26,892 KB
testcase_26 AC 61 ms
26,800 KB
testcase_27 AC 61 ms
26,840 KB
testcase_28 AC 61 ms
26,788 KB
testcase_29 AC 61 ms
26,848 KB
testcase_30 AC 61 ms
26,760 KB
testcase_31 AC 61 ms
26,836 KB
testcase_32 AC 60 ms
26,892 KB
testcase_33 AC 60 ms
26,800 KB
testcase_34 AC 61 ms
26,788 KB
testcase_35 AC 62 ms
26,828 KB
testcase_36 AC 60 ms
26,780 KB
testcase_37 AC 63 ms
26,764 KB
testcase_38 AC 64 ms
26,888 KB
testcase_39 AC 62 ms
26,804 KB
testcase_40 AC 61 ms
26,764 KB
testcase_41 AC 61 ms
26,768 KB
testcase_42 AC 59 ms
26,800 KB
testcase_43 AC 60 ms
26,768 KB
testcase_44 AC 60 ms
26,760 KB
testcase_45 AC 61 ms
26,824 KB
testcase_46 AC 60 ms
26,788 KB
testcase_47 AC 62 ms
26,772 KB
testcase_48 AC 65 ms
26,840 KB
testcase_49 AC 24 ms
7,448 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 6 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 3 ms
4,384 KB
testcase_57 AC 11 ms
5,164 KB
testcase_58 AC 20 ms
7,444 KB
testcase_59 AC 14 ms
5,064 KB
testcase_60 AC 7 ms
4,380 KB
testcase_61 AC 29 ms
7,444 KB
testcase_62 AC 8 ms
4,380 KB
testcase_63 AC 20 ms
7,400 KB
testcase_64 AC 6 ms
4,376 KB
testcase_65 AC 5 ms
4,376 KB
testcase_66 AC 7 ms
4,376 KB
testcase_67 AC 7 ms
4,380 KB
testcase_68 AC 7 ms
4,376 KB
testcase_69 AC 60 ms
26,860 KB
testcase_70 AC 62 ms
26,852 KB
testcase_71 AC 61 ms
26,816 KB
testcase_72 AC 64 ms
26,760 KB
testcase_73 AC 61 ms
26,772 KB
testcase_74 AC 63 ms
26,824 KB
testcase_75 AC 69 ms
26,820 KB
testcase_76 AC 61 ms
26,788 KB
testcase_77 AC 61 ms
26,860 KB
testcase_78 AC 61 ms
26,768 KB
testcase_79 AC 62 ms
27,048 KB
testcase_80 AC 60 ms
26,876 KB
testcase_81 AC 61 ms
26,828 KB
testcase_82 AC 62 ms
26,860 KB
testcase_83 AC 61 ms
26,788 KB
testcase_84 AC 62 ms
26,784 KB
testcase_85 AC 61 ms
26,920 KB
testcase_86 AC 62 ms
26,752 KB
testcase_87 AC 62 ms
26,768 KB
testcase_88 AC 62 ms
26,776 KB
testcase_89 AC 67 ms
27,508 KB
testcase_90 AC 72 ms
27,892 KB
testcase_91 AC 81 ms
28,944 KB
testcase_92 AC 64 ms
26,916 KB
testcase_93 AC 75 ms
28,232 KB
testcase_94 AC 61 ms
27,016 KB
testcase_95 AC 77 ms
28,260 KB
testcase_96 AC 71 ms
27,800 KB
testcase_97 AC 71 ms
27,716 KB
testcase_98 AC 66 ms
27,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll mo=1000000007;
ll combi(ll N_, ll C_) {
	const int NUM_=1000001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}

int M;
vector<ll> H;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>M;
	ll left=M;
	while(cin>>x) H.push_back(x), left-=x;
	
	if(left==M) return _P("1\n");
	
	left-=H.size()-1;
	int pat=H.size()+1;
	
	if(left<0) return _P("NA\n");
	
	cout<<hcomb(pat,left)<<endl;
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0