結果

問題 No.1681 +-*
ユーザー atjh16atjh16
提出日時 2021-09-20 17:14:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 1,382 ms
コンパイル使用メモリ 163,820 KB
実行使用メモリ 5,040 KB
最終ジャッジ日時 2023-09-15 11:37:23
合計ジャッジ時間 5,280 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 61 ms
4,964 KB
testcase_06 AC 62 ms
4,920 KB
testcase_07 AC 61 ms
4,920 KB
testcase_08 AC 97 ms
5,040 KB
testcase_09 AC 98 ms
4,900 KB
testcase_10 AC 97 ms
4,912 KB
testcase_11 AC 97 ms
4,972 KB
testcase_12 AC 97 ms
4,964 KB
testcase_13 AC 49 ms
4,376 KB
testcase_14 AC 97 ms
4,908 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 97 ms
4,912 KB
testcase_18 AC 97 ms
4,960 KB
testcase_19 AC 97 ms
4,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long n, m = 0, t = 1;
long long a[200000];
const long long M = 1e9 + 7;

long long powm(long long a, long long b) {
	long long u = 1, v = a;

	while (b > 0) {
		if (b & 1)
			u = u * v % M;

		v = v * v % M;
		b >>= 1;
	}

	return u;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 0; i < n; i++) {
		t = t * a[i] % M;

		if(i < n - 1)
			m = (m + t * powm(3, n - 2 - i) * 2 % M) % M;
		else
			m = (m + t) % M;
	}

	cout << m << endl;
}
0