結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-09 01:32:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 165,400 KB
実行使用メモリ 20,176 KB
最終ジャッジ日時 2024-04-21 09:05:33
合計ジャッジ時間 8,053 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
19,024 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 41 ms
18,928 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 42 ms
18,932 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 47 ms
19,364 KB
testcase_10 AC 45 ms
19,328 KB
testcase_11 AC 49 ms
19,288 KB
testcase_12 AC 45 ms
19,412 KB
testcase_13 AC 66 ms
19,676 KB
testcase_14 AC 46 ms
19,412 KB
testcase_15 AC 44 ms
19,320 KB
testcase_16 AC 45 ms
19,436 KB
testcase_17 AC 48 ms
19,152 KB
testcase_18 AC 87 ms
20,172 KB
testcase_19 AC 44 ms
19,060 KB
testcase_20 AC 41 ms
19,152 KB
testcase_21 AC 41 ms
19,072 KB
testcase_22 AC 42 ms
19,112 KB
testcase_23 AC 41 ms
19,152 KB
testcase_24 AC 41 ms
19,072 KB
testcase_25 AC 41 ms
19,072 KB
testcase_26 AC 41 ms
19,072 KB
testcase_27 AC 42 ms
19,200 KB
testcase_28 AC 41 ms
18,948 KB
testcase_29 AC 41 ms
18,916 KB
testcase_30 AC 41 ms
19,072 KB
testcase_31 AC 41 ms
19,172 KB
testcase_32 AC 40 ms
18,996 KB
testcase_33 AC 40 ms
19,032 KB
testcase_34 AC 42 ms
19,144 KB
testcase_35 AC 41 ms
19,168 KB
testcase_36 AC 40 ms
19,044 KB
testcase_37 AC 43 ms
18,940 KB
testcase_38 AC 40 ms
19,060 KB
testcase_39 AC 41 ms
19,200 KB
testcase_40 AC 44 ms
19,048 KB
testcase_41 AC 43 ms
19,128 KB
testcase_42 AC 40 ms
19,072 KB
testcase_43 AC 40 ms
19,072 KB
testcase_44 AC 41 ms
19,200 KB
testcase_45 AC 42 ms
19,084 KB
testcase_46 AC 43 ms
19,140 KB
testcase_47 AC 43 ms
19,120 KB
testcase_48 AC 42 ms
19,200 KB
testcase_49 AC 50 ms
5,580 KB
testcase_50 AC 5 ms
5,376 KB
testcase_51 AC 4 ms
5,376 KB
testcase_52 AC 10 ms
5,376 KB
testcase_53 AC 6 ms
5,376 KB
testcase_54 AC 11 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 5 ms
5,376 KB
testcase_57 AC 21 ms
5,376 KB
testcase_58 AC 39 ms
5,456 KB
testcase_59 AC 31 ms
5,376 KB
testcase_60 AC 15 ms
5,376 KB
testcase_61 AC 64 ms
5,576 KB
testcase_62 AC 15 ms
5,376 KB
testcase_63 AC 44 ms
5,376 KB
testcase_64 AC 13 ms
5,376 KB
testcase_65 AC 9 ms
5,376 KB
testcase_66 AC 13 ms
5,376 KB
testcase_67 AC 13 ms
5,376 KB
testcase_68 AC 13 ms
5,376 KB
testcase_69 AC 41 ms
19,160 KB
testcase_70 AC 41 ms
18,952 KB
testcase_71 AC 42 ms
19,072 KB
testcase_72 AC 41 ms
19,000 KB
testcase_73 AC 42 ms
19,200 KB
testcase_74 AC 41 ms
19,048 KB
testcase_75 AC 42 ms
19,148 KB
testcase_76 AC 42 ms
19,072 KB
testcase_77 AC 40 ms
19,092 KB
testcase_78 AC 39 ms
19,072 KB
testcase_79 AC 40 ms
19,200 KB
testcase_80 AC 43 ms
19,072 KB
testcase_81 AC 42 ms
19,052 KB
testcase_82 AC 41 ms
19,176 KB
testcase_83 AC 42 ms
19,104 KB
testcase_84 AC 41 ms
19,060 KB
testcase_85 AC 41 ms
18,920 KB
testcase_86 AC 41 ms
19,072 KB
testcase_87 AC 40 ms
19,132 KB
testcase_88 AC 41 ms
19,184 KB
testcase_89 AC 58 ms
19,284 KB
testcase_90 AC 68 ms
19,664 KB
testcase_91 AC 86 ms
20,176 KB
testcase_92 AC 50 ms
19,284 KB
testcase_93 AC 69 ms
19,696 KB
testcase_94 AC 41 ms
19,072 KB
testcase_95 AC 71 ms
19,788 KB
testcase_96 AC 62 ms
19,536 KB
testcase_97 AC 63 ms
19,528 KB
testcase_98 AC 55 ms
19,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
ll mo = 1000000007;
const int NUM_FAC = 2000001;
ll modfact(ll x) {
	static ll _fact[NUM_FAC + 1];
	if (_fact[0] == 0) {
		_fact[0] = 1;
		for (int i = 1; i <= NUM_FAC; ++i) _fact[i] = _fact[i - 1] * i%mo;
	}
	return _fact[x];
}
ll modpow(ll a, ll n) {
	ll r = 1;
	while (n) r = r*((n % 2) ? a : 1) % mo, a = a*a%mo, n >>= 1;
	return r;
}
ll moddiv(ll a, ll b)
{
	ll ap_2 = modpow(b, mo - 2);
	return (a * ap_2) % mo;
}
ll aCb(ll a, ll b) {
	return moddiv(modfact(a), (modfact(a-b) * modfact(b))%mo);
}
ll nHk(ll n, ll k)
{
	return aCb(n + k - 1, k - 1);
}
//-----------------------------------------------------------------
int M;
vector<int> H;
//-----------------------------------------------------------------
int main() {
	cin >> M;

	int x;
	while (cin >> x) H.push_back(x);

	if (H.size() == 1 && H[0] == 0) {
		printf("1\n");
		return 0;
	}

	int sum = 0;
	rep(i, 0, H.size()) sum += H[i];
	int a = M - sum - (H.size() - 1);
	int b = H.size() + 1;

	if (a < 0) {
		cout << "NA" << endl;
		return 0;
	}

	ll ans = nHk(a, b);
	cout << ans << endl;
}
0