結果

問題 No.794 チーム戦 (2)
ユーザー ei1333333
提出日時 2018-10-06 03:57:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 115 ms / 1,500 ms
コード長 594 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 195,772 KB
最終ジャッジ日時 2025-01-06 14:22:16
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

int N, K, A[200000];
int pos[200000];

int rec(int idx, int k) {
  if(idx + 1 == k) return 1;
  int ret = 0;
  if(pos[idx] - k > 0) (ret += 1LL * rec(idx - 1, k + 1) * (pos[idx] - k) % mod) %= mod;
  return ret;
}

int main() {
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  int ptr = 0;
  for(int i = N - 1; i >= 0; i--) {
    while(ptr < i && A[i] + A[ptr] <= K) ++ptr;
    ptr = min(ptr, i);
    pos[i] = ptr;
  }
  cout << rec(N - 1, 0) << endl;
}

0