結果

問題 No.794 チーム戦 (2)
ユーザー finefine
提出日時 2019-02-22 23:10:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 1,500 ms
コード長 1,414 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 171,732 KB
実行使用メモリ 10,956 KB
最終ジャッジ日時 2023-08-17 04:16:47
合計ジャッジ時間 4,586 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,388 KB
testcase_14 AC 51 ms
10,904 KB
testcase_15 AC 51 ms
10,944 KB
testcase_16 AC 41 ms
4,636 KB
testcase_17 AC 42 ms
4,624 KB
testcase_18 AC 50 ms
10,956 KB
testcase_19 AC 50 ms
10,832 KB
testcase_20 AC 50 ms
10,836 KB
testcase_21 AC 50 ms
10,808 KB
testcase_22 AC 31 ms
7,844 KB
testcase_23 AC 28 ms
7,364 KB
testcase_24 AC 22 ms
6,408 KB
testcase_25 AC 19 ms
5,988 KB
testcase_26 AC 21 ms
6,204 KB
testcase_27 AC 27 ms
10,868 KB
testcase_28 AC 27 ms
10,828 KB
testcase_29 AC 19 ms
4,612 KB
testcase_30 AC 19 ms
4,672 KB
testcase_31 AC 27 ms
10,812 KB
testcase_32 AC 27 ms
10,808 KB
testcase_33 AC 27 ms
10,812 KB
testcase_34 AC 27 ms
10,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll calc(int num, vector<ll>& f, vector<ll>& fi) {
	ll res = 1;
	for (int i = num * 2; i >= 2; i -= 2) {
		ll tmp = i;
		tmp = tmp * (i-1) % MOD * fi[2] % MOD;
		(res *= tmp) %= MOD;
	}
	(res *= fi[num]) %= MOD;
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll K;
	cin >> n >> K;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end(), greater<>());

	bool flag = true;
	for (int i = 0; i < n; i++) {
		int j = n - 1 - i;
		if (j < i) break;
		if (a[i] + a[j] > K) {
			flag = false;
			break;
		}
	}

	if (!flag) {
		cout << 0 << endl;
		return 0;
	}

	vector<ll> f(2 * n + 1, 1), fi(2 * n + 1, 1);
	for (int i = 1; i <= 2*n; i++) {
		f[i] = f[i-1]*i%MOD;
	}
	fi[2*n] = modpow(f[2*n], MOD - 2, MOD);
	for (int i = 2 * n; i > 0; i--) {
		fi[i-1] = fi[i]*i%MOD;
	}

	ll ans = 1;
	for (int i = 0, j = n - 1; i < n; i++) {
		while (j > i + 1) {
			if (a[j-1]+a[i]<=K) j--;
			else break;
		}

		if (j == i + 1) {
			int num = (n - 2 * i) / 2;
			if (num < 0) break;
			(ans *= calc(num, f, fi)) %= MOD;
			break;
		}

		int hoge = n - j - i;
		(ans *= hoge) %= MOD;
	}
	cout << ans << endl;
	return 0;
}
0