結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー naimonon77naimonon77
提出日時 2016-07-23 20:42:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 2,938 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 169,644 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 08:05:52
合計ジャッジ時間 5,227 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 33 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 23 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 34 ms
5,376 KB
testcase_18 AC 41 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 45 ms
5,376 KB
testcase_50 AC 4 ms
5,376 KB
testcase_51 AC 4 ms
5,376 KB
testcase_52 AC 10 ms
5,376 KB
testcase_53 AC 5 ms
5,376 KB
testcase_54 AC 11 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 5 ms
5,376 KB
testcase_57 AC 19 ms
5,376 KB
testcase_58 AC 37 ms
5,376 KB
testcase_59 AC 29 ms
5,376 KB
testcase_60 AC 14 ms
5,376 KB
testcase_61 AC 61 ms
5,376 KB
testcase_62 AC 15 ms
5,376 KB
testcase_63 AC 39 ms
5,376 KB
testcase_64 AC 12 ms
5,376 KB
testcase_65 AC 8 ms
5,376 KB
testcase_66 AC 13 ms
5,376 KB
testcase_67 AC 12 ms
5,376 KB
testcase_68 AC 12 ms
5,376 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 2 ms
5,376 KB
testcase_71 AC 2 ms
5,376 KB
testcase_72 AC 1 ms
5,376 KB
testcase_73 AC 2 ms
5,376 KB
testcase_74 AC 2 ms
5,376 KB
testcase_75 AC 2 ms
5,376 KB
testcase_76 AC 1 ms
5,376 KB
testcase_77 AC 2 ms
5,376 KB
testcase_78 AC 2 ms
5,376 KB
testcase_79 AC 2 ms
5,376 KB
testcase_80 AC 2 ms
5,376 KB
testcase_81 AC 2 ms
5,376 KB
testcase_82 AC 1 ms
5,376 KB
testcase_83 AC 1 ms
5,376 KB
testcase_84 AC 2 ms
5,376 KB
testcase_85 AC 2 ms
5,376 KB
testcase_86 AC 1 ms
5,376 KB
testcase_87 AC 1 ms
5,376 KB
testcase_88 AC 2 ms
5,376 KB
testcase_89 AC 15 ms
5,376 KB
testcase_90 AC 24 ms
5,376 KB
testcase_91 AC 43 ms
5,376 KB
testcase_92 AC 8 ms
5,376 KB
testcase_93 AC 28 ms
5,376 KB
testcase_94 AC 2 ms
5,376 KB
testcase_95 AC 29 ms
5,376 KB
testcase_96 AC 23 ms
5,376 KB
testcase_97 AC 21 ms
5,376 KB
testcase_98 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

/* pow(x,n)はx^nを返すよ! */
template<class T, class U>
T mod_pow(T x, U n) {
	T res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		x %= mod;
		n >>= 1;
		res %= mod;
	}
	return res;
}

template<class T, class U>
T mod_combi(T n, U r) {
	T i;
	T rep = 1;
	if (r > n / 2) r = n - r;
	rep(i, r) {
		rep *= n - i;
		rep %= mod;
		rep *= mod_pow(i + 1, mod - 2);
		rep %= mod;
	}
	return rep;
}
signed main(void)
{
	ull i, j, k, l;
	ull m;
	cin >> m;
	ull cnt = 0;
	int h;
	for(i=0; cin >> h; ++i) {
		cnt += h;
	}
	if (i == 1 && h == 0) {
		cout << 1 << endl;
		return 0;
	}
	if (m - cnt + 1 < i) {
		cout << "NA" << endl;
		return 0;
	}
	cout << mod_combi(m - cnt + 1, i) << endl;
	return 0;
}
0