結果
問題 | No.794 チーム戦 (2) |
ユーザー |
|
提出日時 | 2019-02-22 21:32:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 116 ms / 1,500 ms |
コード長 | 2,764 bytes |
コンパイル時間 | 2,186 ms |
コンパイル使用メモリ | 199,964 KB |
最終ジャッジ日時 | 2025-01-06 21:35:53 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))#define ALL(x) begin(x), end(x)#define dump(x) cerr << #x " = " << x << endlusing ll = long long;using namespace std;template <int32_t MOD>struct mint {int64_t value; // faster than int32_t a littlemint() = default; // value is not initializedmint(int64_t value_) : value(value_) {} // assume value is in proper rangeinline mint<MOD> operator + (mint<MOD> other) const { int64_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }inline mint<MOD> operator - (mint<MOD> other) const { int64_t c = this->value - other.value; return mint<MOD>(c < 0 ? c + MOD : c); }inline mint<MOD> operator * (mint<MOD> other) const { int64_t c = this->value * int64_t(other.value) % MOD; return mint<MOD>(c < 0 ? c + MOD : c);}inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }inline mint<MOD> & operator -= (mint<MOD> other) { this->value -= other.value; if (this->value < 0) this->value += MOD; return *this; }inline mint<MOD> & operator *= (mint<MOD> other) { this->value = this->value * int64_t(other.value) % MOD; if (this->value < 0) this->value += MOD; return *this; }inline mint<MOD> operator - () const { return mint<MOD>(this->value ? MOD - this->value : 0); }mint<MOD> pow(uint64_t k) const {mint<MOD> x = *this, y = 1;for (; k; k >>= 1) {if (k & 1) y *= x;x *= x;}return y;}mint<MOD> inv() const { return pow(MOD - 2); } // MOD must be a primeinline mint<MOD> operator / (mint<MOD> other) const { return *this * other.inv(); }inline mint<MOD> operator /= (mint<MOD> other) { return *this *= other.inv(); }inline bool operator == (mint<MOD> other) const { return value == other.value; }inline bool operator != (mint<MOD> other) const { return value != other.value; }};constexpr int MOD = 1e9 + 7;mint<MOD> solve(int n, ll k, vector<ll> a) {sort(ALL(a));mint<MOD> acc = 1;int l = 0;int r = n - 1;REP (i, n / 2) {int r = n - i - 1;while (l < r and a[l] + a[r] <= k) ++ l;if (l >= r) {acc *= n - 2 * i - 1;} else {acc *= l - i;}}return acc;}int main() {int n; ll k; cin >> n >> k;vector<ll> a(n);REP (i, n) cin >> a[i];cout << solve(n, k, a).value << endl;return 0;}