結果

問題 No.1681 +-*
ユーザー nebukuro09nebukuro09
提出日時 2021-09-17 21:44:53
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 103,928 KB
実行使用メモリ 11,620 KB
最終ジャッジ日時 2023-09-04 14:07:30
合計ジャッジ時間 5,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,048 KB
testcase_01 AC 1 ms
4,988 KB
testcase_02 AC 2 ms
4,984 KB
testcase_03 AC 2 ms
4,992 KB
testcase_04 AC 2 ms
5,056 KB
testcase_05 AC 140 ms
8,124 KB
testcase_06 AC 141 ms
8,112 KB
testcase_07 AC 140 ms
8,148 KB
testcase_08 AC 156 ms
11,572 KB
testcase_09 AC 159 ms
11,620 KB
testcase_10 AC 157 ms
11,564 KB
testcase_11 AC 158 ms
11,568 KB
testcase_12 AC 158 ms
11,612 KB
testcase_13 AC 79 ms
6,184 KB
testcase_14 AC 157 ms
11,616 KB
testcase_15 AC 2 ms
4,988 KB
testcase_16 AC 1 ms
5,052 KB
testcase_17 AC 157 ms
11,568 KB
testcase_18 AC 158 ms
11,588 KB
testcase_19 AC 157 ms
11,588 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;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    long ans = 0;
    long pro = 1;
    long co = 2;
    foreach (i; 0..N-2) co = co * 3 % MOD;

    foreach (i, a; A) {
        pro = pro * a % MOD;
        (ans += pro * co) %= MOD;
        if (i + 2 == N) {
            co = co * powmod(2, MOD-2, MOD) % MOD;
        } else {
            co = co * powmod(3, MOD-2, 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