結果
問題 |
No.794 チーム戦 (2)
|
ユーザー |
|
提出日時 | 2019-02-22 22:56:36 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,368 bytes |
コンパイル時間 | 749 ms |
コンパイル使用メモリ | 122,644 KB |
実行使用メモリ | 16,408 KB |
最終ジャッジ日時 | 2024-06-13 04:11:42 |
合計ジャッジ時間 | 5,087 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 2 WA * 30 |
ソースコード
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 = N-2, k = 0; i >= N / 2; --i, ++k) { j = min(j, i-1); while (j >= 0 && A[i] + A[j] > K) --j; if (j < k) { writeln(0); return; } if (i - j == 1) { int n = N - (k + 1) * 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.writeln; } 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; }