結果

問題 No.1681 +-*
ユーザー forest3forest3
提出日時 2021-11-17 17:58:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 167,748 KB
実行使用メモリ 6,500 KB
最終ジャッジ日時 2023-08-25 12:27:16
合計ジャッジ時間 4,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 44 ms
6,176 KB
testcase_06 AC 44 ms
6,232 KB
testcase_07 AC 44 ms
6,208 KB
testcase_08 AC 79 ms
6,272 KB
testcase_09 AC 79 ms
6,132 KB
testcase_10 AC 80 ms
6,216 KB
testcase_11 AC 78 ms
6,256 KB
testcase_12 AC 79 ms
6,332 KB
testcase_13 AC 40 ms
4,552 KB
testcase_14 AC 79 ms
6,500 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 80 ms
6,180 KB
testcase_18 AC 80 ms
6,168 KB
testcase_19 AC 80 ms
6,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
	int N;
	cin >> N;
	vector<long long> A( N );
	for( int i = 0; i < N; i ++ ) cin >> A[i];

	const long long MOD = 1000000007;
	vector<long long> x3( N );
	x3[0] = 1;
	for( int i = 1; i < N; i++ ) x3[i] = x3[i - 1] * 3 % MOD;
	long long ans = 0;
	long long a = 1;
	for( int i = 0; i < N; i++ ) {
		a *= A[i];
		a %= MOD;
		long long aa = a;
		int n = max( N - 2 - i, 0 ); 
		aa *= x3[n];
		aa %= MOD;
		if( N - 1 - i > 0  ) aa *= 2;
		aa %= MOD;
		ans += aa;
		ans %= MOD;
	}

	cout << ans << endl;
}

0