結果
| 問題 | No.794 チーム戦 (2) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-05-04 15:20:08 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 45 ms / 1,500 ms | 
| コード長 | 809 bytes | 
| コンパイル時間 | 1,610 ms | 
| コンパイル使用メモリ | 171,972 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-22 19:08:17 | 
| 合計ジャッジ時間 | 3,605 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;
bool isFeasible(int N, int K, const vector<int> & As){
    for (int i = 0; i * 2 < N; ++i){
        if (As[i] + As[N - i - 1] > K) return false;
    }
    return true;
}
long long solve(int N, int K, const vector<int> & As){
    if (not isFeasible(N, K, As)) return 0;
    long long ans = 1LL;
    int idx = 0;
    for (int n = N - 1; n > N / 2; --n){
        while (idx < n and As[idx] + As[n] <= K) ++idx;
        --idx;
        (ans *= (idx + 1 - (N - 1 - n))) %= mod;
    }
    return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> As(N, 0);
    for (auto & a : As) cin >> a;
    sort(As.begin(), As.end());
    cout << solve(N, K, As) << endl;
    return 0;
}
            
            
            
        