結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 👑 kmjpkmjp
提出日時 2016-07-08 22:25:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 161,988 KB
実行使用メモリ 29,156 KB
最終ジャッジ日時 2024-04-21 05:50:19
合計ジャッジ時間 8,628 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
26,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 68 ms
26,752 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 69 ms
26,752 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 74 ms
26,992 KB
testcase_10 AC 72 ms
26,992 KB
testcase_11 AC 71 ms
27,236 KB
testcase_12 AC 69 ms
26,880 KB
testcase_13 AC 81 ms
28,004 KB
testcase_14 AC 71 ms
27,236 KB
testcase_15 AC 68 ms
27,008 KB
testcase_16 AC 68 ms
26,880 KB
testcase_17 AC 68 ms
26,988 KB
testcase_18 AC 89 ms
29,060 KB
testcase_19 AC 67 ms
26,752 KB
testcase_20 AC 67 ms
26,752 KB
testcase_21 AC 68 ms
26,752 KB
testcase_22 AC 66 ms
26,752 KB
testcase_23 AC 66 ms
26,752 KB
testcase_24 AC 69 ms
26,752 KB
testcase_25 AC 70 ms
26,752 KB
testcase_26 AC 67 ms
26,624 KB
testcase_27 AC 68 ms
26,752 KB
testcase_28 AC 66 ms
26,752 KB
testcase_29 AC 68 ms
26,752 KB
testcase_30 AC 69 ms
26,752 KB
testcase_31 AC 66 ms
26,752 KB
testcase_32 AC 67 ms
26,752 KB
testcase_33 AC 67 ms
26,752 KB
testcase_34 AC 67 ms
26,752 KB
testcase_35 AC 66 ms
26,752 KB
testcase_36 AC 68 ms
26,624 KB
testcase_37 AC 68 ms
26,752 KB
testcase_38 AC 66 ms
26,752 KB
testcase_39 AC 65 ms
26,752 KB
testcase_40 AC 66 ms
26,752 KB
testcase_41 AC 66 ms
26,752 KB
testcase_42 AC 69 ms
26,752 KB
testcase_43 AC 66 ms
26,752 KB
testcase_44 AC 68 ms
26,752 KB
testcase_45 AC 69 ms
26,752 KB
testcase_46 AC 65 ms
26,752 KB
testcase_47 AC 68 ms
26,752 KB
testcase_48 AC 68 ms
26,752 KB
testcase_49 AC 24 ms
7,356 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 5 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 6 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 3 ms
5,376 KB
testcase_57 AC 12 ms
5,376 KB
testcase_58 AC 21 ms
7,396 KB
testcase_59 AC 16 ms
5,376 KB
testcase_60 AC 8 ms
5,376 KB
testcase_61 AC 31 ms
7,268 KB
testcase_62 AC 8 ms
5,376 KB
testcase_63 AC 21 ms
7,392 KB
testcase_64 AC 6 ms
5,376 KB
testcase_65 AC 4 ms
5,376 KB
testcase_66 AC 7 ms
5,376 KB
testcase_67 AC 7 ms
5,376 KB
testcase_68 AC 7 ms
5,376 KB
testcase_69 AC 68 ms
26,624 KB
testcase_70 AC 67 ms
26,752 KB
testcase_71 AC 67 ms
26,752 KB
testcase_72 AC 65 ms
26,624 KB
testcase_73 AC 67 ms
26,752 KB
testcase_74 AC 67 ms
26,752 KB
testcase_75 AC 70 ms
26,752 KB
testcase_76 AC 68 ms
26,752 KB
testcase_77 AC 67 ms
26,752 KB
testcase_78 AC 65 ms
26,752 KB
testcase_79 AC 65 ms
26,752 KB
testcase_80 AC 71 ms
26,624 KB
testcase_81 AC 62 ms
26,752 KB
testcase_82 AC 60 ms
26,768 KB
testcase_83 AC 70 ms
26,752 KB
testcase_84 AC 68 ms
26,752 KB
testcase_85 AC 66 ms
26,752 KB
testcase_86 AC 65 ms
26,752 KB
testcase_87 AC 68 ms
26,752 KB
testcase_88 AC 66 ms
26,752 KB
testcase_89 AC 75 ms
27,496 KB
testcase_90 AC 79 ms
28,132 KB
testcase_91 AC 91 ms
29,156 KB
testcase_92 AC 69 ms
27,108 KB
testcase_93 AC 79 ms
28,392 KB
testcase_94 AC 67 ms
26,880 KB
testcase_95 AC 82 ms
28,260 KB
testcase_96 AC 78 ms
27,876 KB
testcase_97 AC 79 ms
27,872 KB
testcase_98 AC 73 ms
27,364 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