結果

問題 No.1681 +-*
ユーザー ks2mks2m
提出日時 2021-09-17 21:38:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 828 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 71,332 KB
実行使用メモリ 64,760 KB
最終ジャッジ日時 2023-09-12 07:03:04
合計ジャッジ時間 14,532 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,780 KB
testcase_01 AC 124 ms
56,324 KB
testcase_02 AC 187 ms
55,948 KB
testcase_03 AC 186 ms
56,340 KB
testcase_04 AC 183 ms
55,972 KB
testcase_05 AC 645 ms
64,316 KB
testcase_06 AC 659 ms
64,324 KB
testcase_07 AC 648 ms
64,656 KB
testcase_08 AC 789 ms
64,312 KB
testcase_09 AC 791 ms
64,540 KB
testcase_10 AC 768 ms
64,448 KB
testcase_11 AC 801 ms
64,472 KB
testcase_12 AC 782 ms
64,616 KB
testcase_13 AC 610 ms
60,340 KB
testcase_14 AC 828 ms
64,620 KB
testcase_15 AC 125 ms
55,872 KB
testcase_16 AC 126 ms
55,704 KB
testcase_17 AC 791 ms
64,492 KB
testcase_18 AC 805 ms
64,452 KB
testcase_19 AC 799 ms
64,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int mod = 1000000007;
		long[] p3 = new long[n];
		p3[0] = 1;
		for (int i = 1; i < n; i++) {
			p3[i] = p3[i - 1] * 3;
			p3[i] %= mod;
		}

		long ans = 0;
		long b = 1;
		for (int i = 0; i < n - 1; i++) {
			b *= a[i];
			b %= mod;
			long val = b * p3[n - 2 - i] * 2 % mod;
			ans += val;
		}
		b *= a[n - 1];
		b %= mod;
		ans += b;
		ans %= mod;
		System.out.println(ans);
	}
}
0