結果

問題 No.995 タピオカオイシクナーレ
ユーザー nanaenanae
提出日時 2020-02-21 21:49:24
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,934 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 99,292 KB
実行使用メモリ 4,436 KB
最終ジャッジ日時 2023-09-04 06:04:25
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 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 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 23 ms
4,384 KB
testcase_17 AC 23 ms
4,424 KB
testcase_18 AC 23 ms
4,388 KB
testcase_19 AC 24 ms
4,432 KB
testcase_20 AC 23 ms
4,380 KB
testcase_21 AC 23 ms
4,436 KB
testcase_22 AC 24 ms
4,376 KB
testcase_23 AC 24 ms
4,376 KB
testcase_24 AC 24 ms
4,380 KB
testcase_25 AC 23 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N, M; long K;
    int p, q;
    scan(N, M, K, p, q);
    auto b = iota(N).map!(i => readln.chomp.to!long).array;

    auto y = 2 * p % mod * pow(q, mod - 2) % mod; // 2p / q;
    auto x = 1 - y;
    if (x < 0) x += mod;
    x = pow(x, K);
    auto prk = 1 - x;
    if (prk < 0) prk += mod;
    prk = prk * pow(2, mod - 2) % mod;

    long ans;

    foreach (i ; 0 .. N) {
        if (i < M) {
            auto pp = 1 - prk;
            if (pp < 0) pp += mod;
            (ans += pp * b[i] % mod) %= mod;
        }
        else {
            (ans += prk * b[i] % mod) %= mod;
        }
    }

    writeln(ans);
}


long pow(long x, long y) {
    return y > 0 ? pow(x, y >> 1)^^2 % mod * x^^(y & 1) % mod : 1L;
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
0