結果

問題 No.794 チーム戦 (2)
ユーザー tsutajtsutaj
提出日時 2019-02-22 22:49:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 1,500 ms
コード長 2,123 bytes
コンパイル時間 4,054 ms
コンパイル使用メモリ 107,492 KB
実行使用メモリ 4,756 KB
最終ジャッジ日時 2023-08-16 21:12:10
合計ジャッジ時間 4,626 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,388 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 88 ms
4,624 KB
testcase_15 AC 90 ms
4,600 KB
testcase_16 AC 92 ms
4,728 KB
testcase_17 AC 89 ms
4,752 KB
testcase_18 AC 102 ms
4,576 KB
testcase_19 AC 105 ms
4,756 KB
testcase_20 AC 105 ms
4,752 KB
testcase_21 AC 103 ms
4,628 KB
testcase_22 AC 58 ms
4,384 KB
testcase_23 AC 50 ms
4,376 KB
testcase_24 AC 45 ms
4,376 KB
testcase_25 AC 38 ms
4,376 KB
testcase_26 AC 39 ms
4,376 KB
testcase_27 AC 40 ms
4,652 KB
testcase_28 AC 39 ms
4,596 KB
testcase_29 AC 38 ms
4,548 KB
testcase_30 AC 35 ms
4,540 KB
testcase_31 AC 50 ms
4,600 KB
testcase_32 AC 49 ms
4,688 KB
testcase_33 AC 43 ms
4,632 KB
testcase_34 AC 44 ms
4,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int mod_pow(int n, int k) {
    int res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return res;
}

int calc(int teams) {
    int res = 1;
    for(int i=1; i<=2*teams; i++) {
        (res *= i) %= MOD;
    }
    for(int i=1; i<=teams; i++) {
        (res *= mod_pow(i, MOD-2)) %= MOD;
    }
    int inv2 = mod_pow(2, MOD-2);
    for(int i=1; i<=teams; i++) {
        (res *= inv2) %= MOD;
    }
    return res;
}

signed main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());

    int ans = 1, idx = N-1;
    for(int i=0; i<N/2; i++) {
        if(A[i] + A[i+1] <= K) {
            int teams = (N - 2*i) / 2;
            (ans *= calc(teams)) %= MOD;
            break;
        }
        while(idx > i and A[i] + A[idx] <= K) {
            idx--;
        }

        if(idx == N-1) {
            ans = 0;
            break;
        }
        int rem = N - idx - 1;
        // fprintf(stderr, "i = %lld, idx = %lld, rem = %lld\n", i, idx, rem);
        (ans *= rem - i) %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0