結果

問題 No.794 チーム戦 (2)
ユーザー nebukuro09nebukuro09
提出日時 2019-02-22 22:56:36
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,368 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 108,664 KB
実行使用メモリ 16,720 KB
最終ジャッジ日時 2023-09-03 23:39:28
合計ジャッジ時間 5,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 142 ms
12,496 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
}
0