結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー pekempeypekempey
提出日時 2016-07-08 22:39:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 155,440 KB
実行使用メモリ 69,972 KB
最終ジャッジ日時 2023-08-03 07:03:14
合計ジャッジ時間 11,767 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,200 KB
testcase_01 AC 55 ms
50,272 KB
testcase_02 AC 56 ms
50,364 KB
testcase_03 AC 56 ms
50,220 KB
testcase_04 AC 56 ms
50,268 KB
testcase_05 AC 55 ms
50,384 KB
testcase_06 AC 57 ms
50,324 KB
testcase_07 AC 56 ms
50,216 KB
testcase_08 AC 56 ms
50,264 KB
testcase_09 AC 61 ms
52,740 KB
testcase_10 AC 59 ms
51,544 KB
testcase_11 AC 61 ms
52,668 KB
testcase_12 AC 60 ms
51,588 KB
testcase_13 AC 78 ms
61,196 KB
testcase_14 AC 63 ms
52,764 KB
testcase_15 AC 59 ms
51,564 KB
testcase_16 AC 59 ms
51,532 KB
testcase_17 AC 62 ms
52,676 KB
testcase_18 AC 93 ms
69,972 KB
testcase_19 AC 57 ms
50,336 KB
testcase_20 AC 57 ms
50,352 KB
testcase_21 AC 57 ms
50,368 KB
testcase_22 AC 57 ms
50,336 KB
testcase_23 AC 56 ms
50,368 KB
testcase_24 AC 57 ms
50,332 KB
testcase_25 AC 56 ms
50,476 KB
testcase_26 AC 57 ms
50,212 KB
testcase_27 AC 56 ms
50,412 KB
testcase_28 AC 57 ms
50,396 KB
testcase_29 AC 57 ms
50,264 KB
testcase_30 AC 56 ms
50,212 KB
testcase_31 AC 56 ms
50,384 KB
testcase_32 AC 56 ms
50,316 KB
testcase_33 AC 57 ms
50,264 KB
testcase_34 AC 56 ms
50,324 KB
testcase_35 AC 57 ms
50,452 KB
testcase_36 AC 56 ms
50,376 KB
testcase_37 AC 56 ms
50,388 KB
testcase_38 AC 57 ms
50,412 KB
testcase_39 AC 56 ms
50,316 KB
testcase_40 AC 57 ms
50,216 KB
testcase_41 AC 57 ms
50,416 KB
testcase_42 AC 56 ms
50,356 KB
testcase_43 AC 56 ms
50,368 KB
testcase_44 AC 56 ms
50,368 KB
testcase_45 AC 56 ms
50,272 KB
testcase_46 AC 55 ms
50,196 KB
testcase_47 AC 56 ms
50,412 KB
testcase_48 AC 56 ms
50,212 KB
testcase_49 AC 92 ms
69,228 KB
testcase_50 AC 58 ms
51,132 KB
testcase_51 AC 57 ms
51,144 KB
testcase_52 AC 64 ms
52,864 KB
testcase_53 AC 60 ms
51,596 KB
testcase_54 AC 65 ms
52,888 KB
testcase_55 AC 57 ms
50,716 KB
testcase_56 AC 59 ms
51,520 KB
testcase_57 AC 74 ms
59,420 KB
testcase_58 AC 88 ms
68,580 KB
testcase_59 AC 78 ms
60,596 KB
testcase_60 AC 67 ms
55,632 KB
testcase_61 AC 101 ms
69,144 KB
testcase_62 AC 68 ms
55,776 KB
testcase_63 AC 89 ms
68,884 KB
testcase_64 AC 65 ms
52,820 KB
testcase_65 AC 62 ms
52,744 KB
testcase_66 AC 67 ms
55,672 KB
testcase_67 AC 66 ms
56,124 KB
testcase_68 AC 67 ms
55,740 KB
testcase_69 AC 57 ms
50,332 KB
testcase_70 AC 56 ms
50,408 KB
testcase_71 AC 56 ms
50,148 KB
testcase_72 AC 57 ms
50,264 KB
testcase_73 AC 57 ms
50,388 KB
testcase_74 AC 56 ms
50,336 KB
testcase_75 AC 57 ms
50,384 KB
testcase_76 AC 57 ms
50,352 KB
testcase_77 AC 57 ms
50,336 KB
testcase_78 AC 55 ms
50,260 KB
testcase_79 AC 56 ms
50,328 KB
testcase_80 AC 57 ms
50,388 KB
testcase_81 AC 57 ms
50,320 KB
testcase_82 AC 56 ms
50,156 KB
testcase_83 AC 56 ms
50,216 KB
testcase_84 AC 56 ms
50,324 KB
testcase_85 AC 55 ms
50,456 KB
testcase_86 AC 56 ms
50,448 KB
testcase_87 AC 56 ms
50,264 KB
testcase_88 AC 57 ms
50,212 KB
testcase_89 AC 68 ms
55,428 KB
testcase_90 AC 77 ms
60,608 KB
testcase_91 AC 93 ms
68,672 KB
testcase_92 AC 62 ms
52,720 KB
testcase_93 AC 79 ms
61,084 KB
testcase_94 AC 57 ms
50,736 KB
testcase_95 AC 79 ms
60,208 KB
testcase_96 AC 75 ms
59,896 KB
testcase_97 AC 75 ms
61,212 KB
testcase_98 AC 67 ms
55,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9 + 7;

vector<long long> F, invF;
long long modpow(long long a, long long b, long long mod) {
	long long ret = 1;
	for (; b > 0; a = a * a % mod, b /= 2) if (b & 1) ret = ret * a % mod;
	return ret;
}
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}
void initF(int n) {
	F.resize(n, 1);
	invF.resize(n, 1);
	for (int i = 1; i < n; i++) F[i] = i * F[i - 1] % mod;
	invF[n - 1] = modinv(F[n - 1], mod);
	for (int i = n - 2; i >= 0; i--) invF[i] = invF[i + 1] * (i + 1) % mod;
}
long long P(int a, int b) {
	if (a < b || a < 0 || b < 0) return 0;
	return F[a] * invF[a - b] % mod;
}
long long C(int a, int b) {
	if (a < b || a < 0 || b < 0) return -1;
	return P(a, b) * invF[b] % mod;
}
long long H(int a, int b) {
	if (a == 0 && b == 0) return 1;
	return C(a + b - 1, b);
}

vector<string> split(string s, char d) {
	vector<string> ret;
	for (int i = 0; i <= s.size(); i++) {
		int j = i;
		while (i < s.size() && s[i] != d) i++;
		ret.emplace_back(s.substr(j, i - j));
	}
	return ret;
}

int main() {
	initF(3030303);

	int m;
	cin >> m;
	cin.ignore();

	string s;
	getline(cin, s);
	
	auto ss = split(s, ' ');
	int n = ss.size();

	vector<int> h(n);
	for (int i = 0; i < n; i++) h[i] = stoi(ss[i]);
	for (int i = 0; i < n; i++) m -= h[i] + 1;
	m++;

	if (h[0] == 0) {
		cout << 1 << endl;
	} else {
		int ans = H(n + 1, m);
		if (ans == -1) {
			cout << "NA" << endl;
		} else {
			cout << ans << endl;
		}
	}
}
0