結果

問題 No.794 チーム戦 (2)
ユーザー やむなくやむなく
提出日時 2019-02-22 22:11:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 88 ms / 1,500 ms
コード長 1,386 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 150,932 KB
実行使用メモリ 5,680 KB
最終ジャッジ日時 2023-08-16 19:07:49
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 87 ms
5,408 KB
testcase_15 AC 88 ms
5,540 KB
testcase_16 AC 88 ms
5,544 KB
testcase_17 AC 85 ms
5,400 KB
testcase_18 AC 83 ms
5,356 KB
testcase_19 AC 81 ms
5,680 KB
testcase_20 AC 84 ms
5,488 KB
testcase_21 AC 81 ms
5,420 KB
testcase_22 AC 50 ms
4,484 KB
testcase_23 AC 46 ms
4,384 KB
testcase_24 AC 36 ms
4,380 KB
testcase_25 AC 31 ms
4,384 KB
testcase_26 AC 35 ms
4,380 KB
testcase_27 AC 35 ms
5,476 KB
testcase_28 AC 35 ms
5,356 KB
testcase_29 AC 33 ms
5,464 KB
testcase_30 AC 33 ms
5,484 KB
testcase_31 AC 35 ms
5,348 KB
testcase_32 AC 32 ms
5,364 KB
testcase_33 AC 33 ms
5,408 KB
testcase_34 AC 33 ms
5,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main(){
  LL n,k;
  cin >> n >> k;
  vector<int> a(n);
  vector<LL> fact(n+1);
  fact[0]=1;
  for(int i=1;i<=n;i++){
    fact[i]=fact[i-1]*i%MOD;
  }

  for(int i=0;i<n;i++) cin >> a[i];
  sort(all(a));
  LL ans=1;
  for(int i=n-1;i>=0;i--){
    LL idx=distance(a.begin(),upper_bound(all(a),k-a[i]));
    if(idx-(n-1-i)<=0){
      cout << 0 << endl;
      return 0;
    }
    if(idx>i){
      LL nokori=n-2*(n-1-i);
      LL tmp=nokori/2;
      while(nokori){
        ans=(ans*(nokori*(nokori-1)/2%MOD))%MOD;
        nokori-=2;
      }
      ans=ans*modinv(fact[tmp],MOD)%MOD;
      break;
    }
    ans=(ans*(idx-(n-1-i)))%MOD;
  }
  cout << ans << endl;
  return 0;
}
0