結果
問題 | No.794 チーム戦 (2) |
ユーザー |
|
提出日時 | 2019-02-22 23:06:38 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 189 ms / 1,500 ms |
コード長 | 1,319 bytes |
コンパイル時間 | 813 ms |
コンパイル使用メモリ | 125,504 KB |
実行使用メモリ | 16,128 KB |
最終ジャッジ日時 | 2024-06-13 04:12:14 |
合計ジャッジ時間 | 5,209 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop, core.stdc.string;immutable long MOD = 10^^9 + 7;long[] P2, F, G;void main() {auto s = readln.split.map!(to!int);auto N = s[0];auto K = s[1];auto A = readln.split.map!(to!long).array;A.sort();P2 = new long[](N+1);F = new long[](N+1);G = new long[](N+1);P2[0] = F[0] = G[0] = 1;foreach (i; 1..N+1) P2[i] = P2[i-1] * 2 % MOD;foreach (i; 1..N+1) F[i] = F[i-1] * i % MOD;foreach (i; 1..N+1) G[i] = powmod(F[i], MOD-2, MOD);long ans = 1;for (int i = N-1, j = -1, k = 0; i >= N / 2; --i, ++k) {while (j < i-1 && A[i] + A[j+1] <= K) ++j;if (j < k) {writeln(0);return;}if (i - j == 1) {int n = N - k * 2;ans = ans * F[n] % MOD * powmod(P2[n/2], MOD-2, MOD) % MOD * G[n/2] % MOD;break;}ans = ans * (j - k + 1) % MOD;}ans = (ans % MOD + MOD) % MOD;ans.writeln;}long powmod(long a, long x, long m) {long ret = 1;while (x) {if (x % 2) ret = ret * a % m;a = a * a % m;x /= 2;}return ret;}