結果

問題 No.794 チーム戦 (2)
ユーザー kimiyukikimiyuki
提出日時 2019-02-22 21:32:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 1,500 ms
コード長 2,764 bytes
コンパイル時間 2,301 ms
コンパイル使用メモリ 206,228 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-04 00:01:05
合計ジャッジ時間 4,660 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 93 ms
6,940 KB
testcase_15 AC 90 ms
6,940 KB
testcase_16 AC 92 ms
6,940 KB
testcase_17 AC 94 ms
6,944 KB
testcase_18 AC 94 ms
6,940 KB
testcase_19 AC 95 ms
6,944 KB
testcase_20 AC 95 ms
6,944 KB
testcase_21 AC 97 ms
6,940 KB
testcase_22 AC 59 ms
6,940 KB
testcase_23 AC 50 ms
6,940 KB
testcase_24 AC 38 ms
6,940 KB
testcase_25 AC 33 ms
6,940 KB
testcase_26 AC 35 ms
6,940 KB
testcase_27 AC 35 ms
6,940 KB
testcase_28 AC 36 ms
6,940 KB
testcase_29 AC 34 ms
6,940 KB
testcase_30 AC 34 ms
6,940 KB
testcase_31 AC 35 ms
6,944 KB
testcase_32 AC 35 ms
6,940 KB
testcase_33 AC 35 ms
6,940 KB
testcase_34 AC 35 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 << endl
using ll = long long;
using namespace std;

template <int32_t MOD>
struct mint {
    int64_t value;  // faster than int32_t a little
    mint() = default;  // value is not initialized
    mint(int64_t value_) : value(value_) {}  // assume value is in proper range
    inline 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 prime
    inline 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;
}
0