結果

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

ソースコード

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 = 0; i < N; i++) {
   while(ptr < i && A[i] + A[ptr] <= K) ++ptr;
   pos[i] = ptr;
 }
 cout << rec(N - 1, 0) << endl;
}
0