結果

問題 No.794 チーム戦 (2)
ユーザー kimiyukikimiyuki
提出日時 2019-02-22 21:32:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 1,500 ms
コード長 2,764 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 205,224 KB
実行使用メモリ 6,444 KB
最終ジャッジ日時 2023-08-16 15:50:46
合計ジャッジ時間 5,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 94 ms
6,148 KB
testcase_15 AC 95 ms
6,144 KB
testcase_16 AC 94 ms
6,172 KB
testcase_17 AC 92 ms
6,220 KB
testcase_18 AC 92 ms
6,124 KB
testcase_19 AC 92 ms
6,288 KB
testcase_20 AC 94 ms
6,444 KB
testcase_21 AC 93 ms
6,200 KB
testcase_22 AC 57 ms
4,824 KB
testcase_23 AC 51 ms
4,628 KB
testcase_24 AC 40 ms
4,376 KB
testcase_25 AC 35 ms
4,376 KB
testcase_26 AC 38 ms
4,432 KB
testcase_27 AC 37 ms
6,124 KB
testcase_28 AC 38 ms
6,436 KB
testcase_29 AC 37 ms
6,280 KB
testcase_30 AC 37 ms
6,092 KB
testcase_31 AC 37 ms
6,088 KB
testcase_32 AC 38 ms
6,124 KB
testcase_33 AC 37 ms
6,168 KB
testcase_34 AC 37 ms
6,096 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