結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-09 01:33:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 4,412 ms
コンパイル使用メモリ 168,060 KB
実行使用メモリ 20,012 KB
最終ジャッジ日時 2023-08-03 11:13:54
合計ジャッジ時間 8,208 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
18,996 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 39 ms
18,952 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 40 ms
18,992 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 44 ms
19,060 KB
testcase_10 AC 43 ms
19,064 KB
testcase_11 AC 47 ms
19,180 KB
testcase_12 AC 42 ms
19,116 KB
testcase_13 AC 62 ms
19,500 KB
testcase_14 AC 47 ms
19,116 KB
testcase_15 AC 42 ms
19,076 KB
testcase_16 AC 43 ms
19,164 KB
testcase_17 AC 46 ms
19,208 KB
testcase_18 AC 83 ms
20,012 KB
testcase_19 AC 39 ms
18,940 KB
testcase_20 AC 40 ms
18,960 KB
testcase_21 AC 39 ms
19,004 KB
testcase_22 AC 40 ms
19,080 KB
testcase_23 AC 39 ms
19,100 KB
testcase_24 AC 39 ms
19,028 KB
testcase_25 AC 40 ms
18,944 KB
testcase_26 AC 39 ms
18,996 KB
testcase_27 AC 40 ms
19,208 KB
testcase_28 AC 40 ms
19,128 KB
testcase_29 AC 39 ms
19,084 KB
testcase_30 AC 39 ms
19,092 KB
testcase_31 AC 39 ms
18,956 KB
testcase_32 AC 40 ms
18,960 KB
testcase_33 AC 40 ms
18,940 KB
testcase_34 AC 39 ms
19,036 KB
testcase_35 AC 39 ms
19,248 KB
testcase_36 AC 39 ms
18,980 KB
testcase_37 AC 39 ms
18,948 KB
testcase_38 AC 39 ms
18,944 KB
testcase_39 AC 39 ms
18,960 KB
testcase_40 AC 40 ms
18,980 KB
testcase_41 AC 39 ms
19,008 KB
testcase_42 AC 38 ms
18,956 KB
testcase_43 AC 39 ms
18,956 KB
testcase_44 AC 39 ms
18,996 KB
testcase_45 AC 39 ms
19,120 KB
testcase_46 AC 39 ms
18,944 KB
testcase_47 AC 39 ms
18,992 KB
testcase_48 AC 39 ms
18,956 KB
testcase_49 AC 47 ms
5,116 KB
testcase_50 AC 4 ms
4,380 KB
testcase_51 AC 4 ms
4,380 KB
testcase_52 AC 10 ms
4,376 KB
testcase_53 AC 6 ms
4,380 KB
testcase_54 AC 12 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 5 ms
4,380 KB
testcase_57 AC 21 ms
4,380 KB
testcase_58 AC 39 ms
5,192 KB
testcase_59 AC 30 ms
4,380 KB
testcase_60 AC 14 ms
4,380 KB
testcase_61 AC 63 ms
5,228 KB
testcase_62 AC 15 ms
4,384 KB
testcase_63 AC 40 ms
5,192 KB
testcase_64 AC 11 ms
4,376 KB
testcase_65 AC 8 ms
4,380 KB
testcase_66 AC 13 ms
4,376 KB
testcase_67 AC 13 ms
4,380 KB
testcase_68 AC 13 ms
4,380 KB
testcase_69 AC 39 ms
19,124 KB
testcase_70 AC 40 ms
18,976 KB
testcase_71 AC 40 ms
19,024 KB
testcase_72 AC 40 ms
18,956 KB
testcase_73 AC 40 ms
18,980 KB
testcase_74 AC 39 ms
18,944 KB
testcase_75 AC 39 ms
19,244 KB
testcase_76 AC 41 ms
19,016 KB
testcase_77 AC 40 ms
19,244 KB
testcase_78 AC 40 ms
18,976 KB
testcase_79 AC 40 ms
18,996 KB
testcase_80 AC 39 ms
18,972 KB
testcase_81 AC 39 ms
18,940 KB
testcase_82 AC 40 ms
19,212 KB
testcase_83 AC 39 ms
18,940 KB
testcase_84 AC 39 ms
18,976 KB
testcase_85 AC 40 ms
19,124 KB
testcase_86 AC 39 ms
18,940 KB
testcase_87 AC 39 ms
18,980 KB
testcase_88 AC 40 ms
18,944 KB
testcase_89 AC 58 ms
19,352 KB
testcase_90 AC 64 ms
19,516 KB
testcase_91 AC 83 ms
19,920 KB
testcase_92 AC 46 ms
19,072 KB
testcase_93 AC 67 ms
19,396 KB
testcase_94 AC 40 ms
18,988 KB
testcase_95 AC 68 ms
19,492 KB
testcase_96 AC 62 ms
19,408 KB
testcase_97 AC 61 ms
19,444 KB
testcase_98 AC 51 ms
19,228 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 MOD = 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%MOD;
	}
	return _fact[x];
}
ll modpow(ll a, ll n) {
	ll r = 1;
	while (n) r = r*((n % 2) ? a : 1) % MOD, a = a*a%MOD, n >>= 1;
	return r;
}
ll moddiv(ll a, ll b)
{
	ll ap_2 = modpow(b, MOD - 2);
	return (a * ap_2) % MOD;
}
ll aCb(ll a, ll b) {
	return moddiv(modfact(a), (modfact(a-b) * modfact(b))% MOD);
}
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