結果

問題 No.1681 +-*
ユーザー tentententen
提出日時 2021-10-19 08:58:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 4,689 ms
コンパイル使用メモリ 76,904 KB
実行使用メモリ 66,248 KB
最終ジャッジ日時 2023-10-20 10:38:29
合計ジャッジ時間 11,212 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,348 KB
testcase_01 AC 53 ms
53,344 KB
testcase_02 AC 58 ms
53,388 KB
testcase_03 AC 58 ms
53,380 KB
testcase_04 AC 58 ms
53,384 KB
testcase_05 AC 236 ms
59,456 KB
testcase_06 AC 235 ms
59,472 KB
testcase_07 AC 237 ms
61,520 KB
testcase_08 AC 291 ms
66,184 KB
testcase_09 AC 294 ms
66,040 KB
testcase_10 AC 290 ms
65,992 KB
testcase_11 AC 292 ms
66,084 KB
testcase_12 AC 300 ms
66,064 KB
testcase_13 AC 222 ms
60,380 KB
testcase_14 AC 287 ms
66,216 KB
testcase_15 AC 54 ms
53,380 KB
testcase_16 AC 54 ms
53,356 KB
testcase_17 AC 292 ms
66,248 KB
testcase_18 AC 292 ms
66,104 KB
testcase_19 AC 292 ms
66,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long[] qubes = new long[n + 1];
        qubes[1] = 1;
        for (int i = 2; i <= n; i++) {
            qubes[i] = qubes[i - 1] * 3 % MOD;
        }
        long base = 1;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            base *= sc.nextInt();
            base %= MOD;
            ans += base * ((qubes[n - i] - qubes[n - i - 1] + MOD) % MOD) % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0