結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー pekempeypekempey
提出日時 2016-07-08 22:39:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 168,024 KB
実行使用メモリ 69,268 KB
最終ジャッジ日時 2024-04-21 06:05:02
合計ジャッジ時間 11,971 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
50,560 KB
testcase_01 AC 77 ms
50,560 KB
testcase_02 AC 74 ms
50,560 KB
testcase_03 AC 76 ms
50,560 KB
testcase_04 AC 75 ms
50,432 KB
testcase_05 AC 75 ms
50,432 KB
testcase_06 AC 74 ms
50,560 KB
testcase_07 AC 75 ms
50,560 KB
testcase_08 AC 74 ms
50,560 KB
testcase_09 AC 80 ms
52,972 KB
testcase_10 AC 78 ms
51,772 KB
testcase_11 AC 81 ms
53,016 KB
testcase_12 AC 77 ms
51,892 KB
testcase_13 AC 98 ms
59,616 KB
testcase_14 AC 80 ms
53,032 KB
testcase_15 AC 77 ms
51,880 KB
testcase_16 AC 78 ms
51,892 KB
testcase_17 AC 80 ms
53,004 KB
testcase_18 AC 116 ms
68,732 KB
testcase_19 AC 82 ms
50,560 KB
testcase_20 AC 75 ms
50,560 KB
testcase_21 AC 75 ms
50,560 KB
testcase_22 AC 75 ms
50,560 KB
testcase_23 AC 74 ms
50,560 KB
testcase_24 AC 74 ms
50,560 KB
testcase_25 AC 74 ms
50,560 KB
testcase_26 AC 74 ms
50,560 KB
testcase_27 AC 74 ms
50,432 KB
testcase_28 AC 75 ms
50,560 KB
testcase_29 AC 75 ms
50,560 KB
testcase_30 AC 75 ms
50,560 KB
testcase_31 AC 75 ms
50,560 KB
testcase_32 AC 75 ms
50,560 KB
testcase_33 AC 75 ms
50,560 KB
testcase_34 AC 75 ms
50,432 KB
testcase_35 AC 75 ms
50,560 KB
testcase_36 AC 75 ms
50,560 KB
testcase_37 AC 75 ms
50,560 KB
testcase_38 AC 75 ms
50,432 KB
testcase_39 AC 74 ms
50,560 KB
testcase_40 AC 75 ms
50,432 KB
testcase_41 AC 75 ms
50,560 KB
testcase_42 AC 75 ms
50,560 KB
testcase_43 AC 75 ms
50,432 KB
testcase_44 AC 75 ms
50,560 KB
testcase_45 AC 75 ms
50,560 KB
testcase_46 AC 74 ms
50,560 KB
testcase_47 AC 75 ms
50,560 KB
testcase_48 AC 75 ms
50,560 KB
testcase_49 AC 118 ms
68,824 KB
testcase_50 AC 77 ms
51,328 KB
testcase_51 AC 76 ms
51,328 KB
testcase_52 AC 84 ms
53,100 KB
testcase_53 AC 81 ms
51,780 KB
testcase_54 AC 85 ms
53,176 KB
testcase_55 AC 76 ms
50,944 KB
testcase_56 AC 78 ms
51,888 KB
testcase_57 AC 96 ms
59,608 KB
testcase_58 AC 111 ms
68,580 KB
testcase_59 AC 98 ms
59,888 KB
testcase_60 AC 86 ms
55,216 KB
testcase_61 AC 129 ms
69,268 KB
testcase_62 AC 86 ms
55,232 KB
testcase_63 AC 114 ms
68,620 KB
testcase_64 AC 83 ms
53,156 KB
testcase_65 AC 80 ms
52,980 KB
testcase_66 AC 86 ms
55,100 KB
testcase_67 AC 85 ms
55,164 KB
testcase_68 AC 86 ms
55,232 KB
testcase_69 AC 74 ms
50,560 KB
testcase_70 AC 75 ms
50,560 KB
testcase_71 AC 75 ms
50,688 KB
testcase_72 AC 75 ms
50,432 KB
testcase_73 AC 74 ms
50,432 KB
testcase_74 AC 75 ms
50,560 KB
testcase_75 AC 74 ms
50,560 KB
testcase_76 AC 74 ms
50,560 KB
testcase_77 AC 74 ms
50,560 KB
testcase_78 AC 75 ms
50,560 KB
testcase_79 AC 74 ms
50,560 KB
testcase_80 AC 75 ms
50,560 KB
testcase_81 AC 75 ms
50,432 KB
testcase_82 AC 75 ms
50,560 KB
testcase_83 AC 75 ms
50,560 KB
testcase_84 AC 74 ms
50,560 KB
testcase_85 AC 75 ms
50,560 KB
testcase_86 AC 75 ms
50,432 KB
testcase_87 AC 75 ms
50,560 KB
testcase_88 AC 75 ms
50,560 KB
testcase_89 AC 87 ms
55,280 KB
testcase_90 AC 98 ms
59,788 KB
testcase_91 AC 119 ms
68,776 KB
testcase_92 AC 80 ms
53,008 KB
testcase_93 AC 101 ms
59,736 KB
testcase_94 AC 74 ms
50,768 KB
testcase_95 AC 102 ms
59,904 KB
testcase_96 AC 94 ms
59,592 KB
testcase_97 AC 97 ms
59,672 KB
testcase_98 AC 85 ms
55,208 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