結果
問題 | No.995 タピオカオイシクナーレ |
ユーザー | nanae |
提出日時 | 2020-02-21 23:55:01 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 5,178 bytes |
コンパイル時間 | 1,539 ms |
コンパイル使用メモリ | 150,248 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 05:29:41 |
合計ジャッジ時間 | 2,692 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 25 ms
6,940 KB |
testcase_17 | AC | 24 ms
6,940 KB |
testcase_18 | AC | 24 ms
6,944 KB |
testcase_19 | AC | 24 ms
6,944 KB |
testcase_20 | AC | 25 ms
6,940 KB |
testcase_21 | AC | 24 ms
6,944 KB |
testcase_22 | AC | 24 ms
6,944 KB |
testcase_23 | AC | 25 ms
6,944 KB |
testcase_24 | AC | 25 ms
6,940 KB |
testcase_25 | AC | 24 ms
6,940 KB |
ソースコード
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 => ModInt(readln.chomp.to!long)).array; auto pr = (ModInt(1) - (ModInt(1) - (ModInt(2) * ModInt(p) / ModInt(q)))^^K) / ModInt(2); ModInt ans = 0; foreach (i ; 0 .. N) { if (i < M) { ans += (ModInt(1) - pr) * b[i]; } else { ans += pr * b[i]; } } writeln(ans); } struct ModInt { long value = 0; long mod = 1_000_000_007L; this(long value, long mod = 1_000_000_007L) { this.mod = mod; this.value = (value % mod); if (this.value < 0) this.value += mod; } long powmod(long x, long y) { return y > 0 ? powmod(x, y >> 1)^^2 % mod * x^^(y & 1) % mod : 1L; } void opAssign(long x) { value = x % mod; if (value < 0) value += mod; } ModInt opBinary(string op)(const ModInt rhs){ auto lhs = this; static if (op == "+") { lhs.value += rhs.value; if (lhs.value >= mod) lhs.value -= mod; return lhs; } static if (op == "-") { lhs.value -= rhs.value; if (lhs.value < 0) lhs.value += mod; return lhs; } static if (op == "*") { (lhs.value *= rhs.value) %= mod; return lhs; } static if (op == "/") { (lhs.value *= powmod(rhs.value, mod - 2)) %= mod; return lhs; } } ModInt opBinary(string op)(long rhs){ auto lhs = this; static if (op != "^^") { rhs %= mod; if (rhs < 0) rhs += mod; } static if (op == "+") { lhs.value += rhs; if (lhs.value >= mod) lhs.value -= mod; return lhs; } static if (op == "-") { lhs.value -= rhs; if (lhs.value < 0) lhs.value += mod; return lhs; } static if (op == "*") { (lhs.value *= rhs) %= mod; return lhs; } static if (op == "/") { (lhs.value *= powmod(rhs, mod - 2)) %= mod; return lhs; } static if (op == "^^") { lhs.value = powmod(lhs.value, rhs); return lhs; } } bool opEquals(ModInt a, ModInt b) { return a.value == b.value; } bool opEquals(T)(const T rhs) { long x = rhs % mod; if (x < 0) x += mod; return this.value == x; } void opOpAssign(string op)(const ModInt rhs) { static if (op == "+") { this.value += rhs.value; if (this.value >= mod) this.value -= mod; } static if (op == "-") { this.value -= rhs.value; if (this.value < 0) this.value += mod; } static if (op == "*") { (this.value *= rhs.value) %= mod; } static if (op == "/") { (this.value *= powmod(rhs.value, mod - 2)) %= mod; } } void opOpAssign(string op)(long rhs) { rhs %= mod; if (rhs < 0) rhs += mod; static if (op == "+") { this.value += rhs; if (this.value >= mod) this.value -= mod; } static if (op == "-") { this.value -= rhs; if (this.value < 0) this.value += mod; } static if (op == "*") { (this.value *= rhs) %= mod; } static if (op == "/") { (this.value *= powmod(rhs, mod - 2)) %= mod; } } string toString() { import std.conv : to; return value.to!string; } } unittest { enum mod = 1_000_000_007L; auto a = ModInt(2); auto b = ModInt(3); assert(a + b == 5); assert(a - b == mod - 1); assert(a * b == 6); assert(a + 8 == 10); assert(a - 1 == 1); assert(a * 7 == 14); ModInt c = 8; assert(c == 8); } 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; }