結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-08 23:05:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 51,384 KB
最終ジャッジ日時 2023-08-03 09:03:01
合計ジャッジ時間 18,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
50,224 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 170 ms
50,228 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 170 ms
50,544 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 179 ms
50,412 KB
testcase_10 AC 177 ms
50,344 KB
testcase_11 AC 185 ms
50,348 KB
testcase_12 AC 179 ms
50,344 KB
testcase_13 AC 199 ms
50,684 KB
testcase_14 AC 183 ms
50,428 KB
testcase_15 AC 175 ms
50,624 KB
testcase_16 AC 179 ms
50,400 KB
testcase_17 AC 179 ms
50,536 KB
testcase_18 AC 217 ms
51,384 KB
testcase_19 AC 172 ms
50,412 KB
testcase_20 AC 177 ms
50,536 KB
testcase_21 AC 171 ms
50,228 KB
testcase_22 AC 175 ms
50,224 KB
testcase_23 AC 171 ms
50,288 KB
testcase_24 AC 170 ms
50,268 KB
testcase_25 AC 169 ms
50,236 KB
testcase_26 AC 168 ms
50,408 KB
testcase_27 AC 172 ms
50,208 KB
testcase_28 AC 173 ms
50,216 KB
testcase_29 AC 173 ms
50,344 KB
testcase_30 AC 182 ms
50,208 KB
testcase_31 AC 176 ms
50,272 KB
testcase_32 AC 173 ms
50,252 KB
testcase_33 AC 172 ms
50,224 KB
testcase_34 AC 167 ms
50,416 KB
testcase_35 AC 169 ms
50,216 KB
testcase_36 AC 169 ms
50,208 KB
testcase_37 AC 172 ms
50,348 KB
testcase_38 AC 168 ms
50,236 KB
testcase_39 AC 172 ms
50,352 KB
testcase_40 AC 171 ms
50,220 KB
testcase_41 AC 172 ms
50,216 KB
testcase_42 AC 174 ms
50,216 KB
testcase_43 AC 171 ms
50,236 KB
testcase_44 AC 171 ms
50,268 KB
testcase_45 AC 174 ms
50,276 KB
testcase_46 AC 172 ms
50,348 KB
testcase_47 AC 173 ms
50,276 KB
testcase_48 AC 175 ms
50,352 KB
testcase_49 AC 48 ms
5,236 KB
testcase_50 AC 4 ms
4,380 KB
testcase_51 AC 4 ms
4,380 KB
testcase_52 AC 10 ms
4,380 KB
testcase_53 AC 5 ms
4,380 KB
testcase_54 AC 12 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 5 ms
4,376 KB
testcase_57 AC 21 ms
4,376 KB
testcase_58 AC 39 ms
5,044 KB
testcase_59 AC 30 ms
4,380 KB
testcase_60 AC 15 ms
4,380 KB
testcase_61 AC 64 ms
5,236 KB
testcase_62 AC 15 ms
4,380 KB
testcase_63 AC 41 ms
5,056 KB
testcase_64 AC 12 ms
4,376 KB
testcase_65 AC 8 ms
4,380 KB
testcase_66 AC 13 ms
4,380 KB
testcase_67 AC 13 ms
4,380 KB
testcase_68 AC 13 ms
4,388 KB
testcase_69 AC 175 ms
50,204 KB
testcase_70 AC 171 ms
50,224 KB
testcase_71 AC 171 ms
50,300 KB
testcase_72 AC 169 ms
50,416 KB
testcase_73 AC 175 ms
50,276 KB
testcase_74 AC 175 ms
50,412 KB
testcase_75 AC 169 ms
50,520 KB
testcase_76 AC 172 ms
50,284 KB
testcase_77 AC 171 ms
50,276 KB
testcase_78 AC 174 ms
50,412 KB
testcase_79 AC 175 ms
50,408 KB
testcase_80 AC 175 ms
50,280 KB
testcase_81 AC 177 ms
50,288 KB
testcase_82 AC 181 ms
50,284 KB
testcase_83 AC 180 ms
50,272 KB
testcase_84 AC 182 ms
50,232 KB
testcase_85 AC 175 ms
50,260 KB
testcase_86 AC 175 ms
50,280 KB
testcase_87 AC 178 ms
50,228 KB
testcase_88 AC 176 ms
50,232 KB
testcase_89 AC 198 ms
50,496 KB
testcase_90 AC 199 ms
50,864 KB
testcase_91 AC 217 ms
51,380 KB
testcase_92 AC 180 ms
50,348 KB
testcase_93 AC 200 ms
50,732 KB
testcase_94 AC 170 ms
50,552 KB
testcase_95 AC 202 ms
50,812 KB
testcase_96 AC 198 ms
50,856 KB
testcase_97 AC 197 ms
50,856 KB
testcase_98 AC 192 ms
50,464 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;
//-----------------------------------------------------------------
ll combi(ll N_, ll C_) {
	const int NUM_ = 2000001;
	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 nHk(ll n, ll k)
{
	return combi(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;
	}

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