結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 186 ms
15,768 KB
testcase_17 AC 185 ms
15,744 KB
testcase_18 AC 246 ms
14,724 KB
testcase_19 AC 244 ms
16,336 KB
testcase_20 AC 244 ms
16,660 KB
testcase_21 AC 244 ms
14,704 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 165 ms
12,540 KB
testcase_30 AC 142 ms
12,528 KB
testcase_31 AC 200 ms
12,744 KB
testcase_32 AC 199 ms
12,748 KB
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 = F[N] * powmod(P2[N/2], MOD-2, MOD) % MOD * G[N/2] % MOD;

    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;
        }
        long tmp = i - j - 1;
        long n = i - k - 1;
        tmp = tmp * F[n] % MOD * powmod(P2[n/2], MOD-2, MOD) % MOD * G[n/2] % MOD;
        ans -= tmp;
        ans %= MOD;
    }

    ans = (ans + 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