結果

問題 No.794 チーム戦 (2)
ユーザー finefine
提出日時 2019-02-22 23:10:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 1,500 ms
コード長 1,414 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 173,080 KB
実行使用メモリ 11,196 KB
最終ジャッジ日時 2024-05-04 11:21:43
合計ジャッジ時間 3,420 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,948 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 42 ms
11,084 KB
testcase_15 AC 44 ms
11,196 KB
testcase_16 AC 36 ms
6,944 KB
testcase_17 AC 36 ms
6,940 KB
testcase_18 AC 45 ms
11,012 KB
testcase_19 AC 43 ms
10,864 KB
testcase_20 AC 42 ms
11,036 KB
testcase_21 AC 42 ms
10,992 KB
testcase_22 AC 28 ms
7,808 KB
testcase_23 AC 24 ms
7,552 KB
testcase_24 AC 18 ms
6,944 KB
testcase_25 AC 16 ms
6,940 KB
testcase_26 AC 18 ms
6,940 KB
testcase_27 AC 24 ms
10,900 KB
testcase_28 AC 24 ms
10,892 KB
testcase_29 AC 17 ms
6,940 KB
testcase_30 AC 17 ms
6,940 KB
testcase_31 AC 25 ms
11,032 KB
testcase_32 AC 24 ms
11,172 KB
testcase_33 AC 23 ms
11,012 KB
testcase_34 AC 23 ms
11,132 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