結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-09 00:36:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 165,512 KB
実行使用メモリ 51,532 KB
最終ジャッジ日時 2024-04-21 09:01:10
合計ジャッジ時間 15,653 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
50,304 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 146 ms
50,432 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 143 ms
50,304 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 143 ms
50,560 KB
testcase_10 AC 149 ms
50,688 KB
testcase_11 AC 153 ms
50,528 KB
testcase_12 AC 150 ms
50,560 KB
testcase_13 AC 174 ms
50,892 KB
testcase_14 AC 150 ms
50,652 KB
testcase_15 AC 146 ms
50,560 KB
testcase_16 AC 150 ms
50,688 KB
testcase_17 AC 152 ms
50,532 KB
testcase_18 AC 192 ms
51,404 KB
testcase_19 AC 151 ms
50,560 KB
testcase_20 AC 142 ms
50,432 KB
testcase_21 AC 148 ms
50,432 KB
testcase_22 AC 151 ms
50,432 KB
testcase_23 AC 140 ms
50,432 KB
testcase_24 AC 152 ms
50,304 KB
testcase_25 AC 150 ms
50,304 KB
testcase_26 AC 142 ms
50,432 KB
testcase_27 AC 146 ms
50,304 KB
testcase_28 AC 146 ms
50,432 KB
testcase_29 AC 144 ms
50,432 KB
testcase_30 AC 144 ms
50,432 KB
testcase_31 AC 148 ms
50,304 KB
testcase_32 AC 148 ms
50,432 KB
testcase_33 AC 141 ms
50,304 KB
testcase_34 AC 146 ms
50,304 KB
testcase_35 AC 160 ms
50,432 KB
testcase_36 AC 149 ms
50,304 KB
testcase_37 AC 153 ms
50,432 KB
testcase_38 AC 152 ms
50,432 KB
testcase_39 AC 144 ms
50,304 KB
testcase_40 AC 162 ms
50,304 KB
testcase_41 AC 151 ms
50,432 KB
testcase_42 AC 145 ms
50,304 KB
testcase_43 AC 166 ms
50,304 KB
testcase_44 AC 155 ms
50,432 KB
testcase_45 AC 160 ms
50,432 KB
testcase_46 AC 171 ms
50,304 KB
testcase_47 AC 169 ms
50,304 KB
testcase_48 AC 177 ms
50,432 KB
testcase_49 AC 53 ms
5,452 KB
testcase_50 AC 5 ms
5,376 KB
testcase_51 AC 5 ms
5,376 KB
testcase_52 AC 12 ms
5,376 KB
testcase_53 AC 6 ms
5,376 KB
testcase_54 AC 14 ms
5,376 KB
testcase_55 AC 3 ms
5,376 KB
testcase_56 AC 5 ms
5,376 KB
testcase_57 AC 23 ms
5,376 KB
testcase_58 AC 43 ms
5,580 KB
testcase_59 AC 34 ms
5,376 KB
testcase_60 AC 16 ms
5,376 KB
testcase_61 AC 70 ms
5,580 KB
testcase_62 AC 16 ms
5,376 KB
testcase_63 AC 45 ms
5,456 KB
testcase_64 AC 14 ms
5,376 KB
testcase_65 AC 8 ms
5,376 KB
testcase_66 AC 15 ms
5,376 KB
testcase_67 AC 14 ms
5,376 KB
testcase_68 AC 14 ms
5,376 KB
testcase_69 AC 156 ms
50,304 KB
testcase_70 AC 160 ms
50,432 KB
testcase_71 AC 161 ms
50,432 KB
testcase_72 AC 152 ms
50,432 KB
testcase_73 AC 152 ms
50,432 KB
testcase_74 AC 148 ms
50,432 KB
testcase_75 AC 151 ms
50,432 KB
testcase_76 AC 157 ms
50,304 KB
testcase_77 AC 151 ms
50,304 KB
testcase_78 AC 145 ms
50,304 KB
testcase_79 AC 152 ms
50,304 KB
testcase_80 AC 141 ms
50,432 KB
testcase_81 AC 143 ms
50,432 KB
testcase_82 AC 144 ms
50,432 KB
testcase_83 AC 140 ms
50,304 KB
testcase_84 AC 137 ms
50,432 KB
testcase_85 AC 143 ms
50,304 KB
testcase_86 AC 145 ms
50,432 KB
testcase_87 AC 146 ms
50,432 KB
testcase_88 AC 148 ms
50,304 KB
testcase_89 AC 163 ms
50,632 KB
testcase_90 AC 170 ms
50,892 KB
testcase_91 AC 191 ms
51,532 KB
testcase_92 AC 148 ms
50,524 KB
testcase_93 AC 172 ms
51,016 KB
testcase_94 AC 153 ms
50,560 KB
testcase_95 AC 176 ms
51,024 KB
testcase_96 AC 164 ms
50,764 KB
testcase_97 AC 163 ms
50,636 KB
testcase_98 AC 158 ms
50,660 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 aCb(ll a, ll b) {
	static ll fact[NUM_FAC + 1], factr[NUM_FAC + 1], inv[NUM_FAC + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_FAC; ++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i = 1; i <= NUM_FAC; ++i) fact[i] = fact[i - 1] * i%mo, factr[i] = factr[i - 1] * inv[i] % mo;
	}
	if (b<0 || b>a) return 0;
	return factr[b] * fact[a] % mo*factr[a - 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