結果

問題 No.1681 +-*
ユーザー rabimearabimea
提出日時 2023-02-15 18:28:39
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 205,092 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 19:51:18
合計ジャッジ時間 6,013 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 82 ms
4,376 KB
testcase_06 AC 82 ms
4,376 KB
testcase_07 AC 81 ms
4,384 KB
testcase_08 AC 106 ms
4,380 KB
testcase_09 AC 107 ms
4,380 KB
testcase_10 AC 107 ms
4,380 KB
testcase_11 AC 107 ms
4,376 KB
testcase_12 AC 107 ms
4,376 KB
testcase_13 AC 53 ms
4,376 KB
testcase_14 AC 107 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 107 ms
4,380 KB
testcase_18 AC 107 ms
4,384 KB
testcase_19 AC 107 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

int readInt() {
	int x;
	readf!" %d"(x);
	return x;
}

const long P = (1e9 + 7).to!long;
long qpow(long a, long b, long m = P) {
	long r = 1 % P, t = a % P;
	for(; b; b /= 2) {
		if(b & 1)
			r = r * t % P;
		t = t * t % P;
	}
	return r;
}

void main() {
	int n = readInt;
	auto a = new int[](n).map!(i => readInt);
	
	long ans = 0, mul = 1;
	foreach(i; 0 .. n) {
		mul = mul * a[i] % P;
		if(i + 1 < n) {
			ans += mul * 2 * qpow(3, n - i - 2) % P;
		} else {
			ans += mul;
		}
		ans %= P;
	}
	writeln(ans);
}

0