結果

問題 No.794 チーム戦 (2)
ユーザー nebukuro09nebukuro09
提出日時 2019-02-22 23:06:38
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 190 ms / 1,500 ms
コード長 1,319 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 108,652 KB
実行使用メモリ 16,492 KB
最終ジャッジ日時 2023-09-03 23:39:57
合計ジャッジ時間 5,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 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,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 189 ms
15,328 KB
testcase_15 AC 190 ms
14,832 KB
testcase_16 AC 189 ms
16,280 KB
testcase_17 AC 187 ms
14,532 KB
testcase_18 AC 188 ms
15,292 KB
testcase_19 AC 189 ms
14,676 KB
testcase_20 AC 188 ms
15,240 KB
testcase_21 AC 188 ms
16,492 KB
testcase_22 AC 113 ms
9,628 KB
testcase_23 AC 101 ms
9,168 KB
testcase_24 AC 80 ms
9,044 KB
testcase_25 AC 69 ms
7,280 KB
testcase_26 AC 75 ms
9,036 KB
testcase_27 AC 142 ms
12,456 KB
testcase_28 AC 142 ms
12,956 KB
testcase_29 AC 141 ms
12,520 KB
testcase_30 AC 141 ms
12,488 KB
testcase_31 AC 142 ms
12,484 KB
testcase_32 AC 142 ms
12,524 KB
testcase_33 AC 142 ms
12,616 KB
testcase_34 AC 141 ms
12,496 KB
権限があれば一括ダウンロードができます

ソースコード

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