結果

問題 No.1681 +-*
ユーザー merlinmerlin
提出日時 2021-09-17 22:23:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 73,792 KB
実行使用メモリ 71,900 KB
最終ジャッジ日時 2023-09-12 08:12:43
合計ジャッジ時間 7,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,252 KB
testcase_01 AC 42 ms
49,160 KB
testcase_02 AC 49 ms
49,336 KB
testcase_03 AC 50 ms
49,320 KB
testcase_04 AC 49 ms
49,516 KB
testcase_05 AC 292 ms
66,572 KB
testcase_06 AC 288 ms
67,112 KB
testcase_07 AC 304 ms
67,340 KB
testcase_08 AC 320 ms
71,900 KB
testcase_09 AC 311 ms
71,744 KB
testcase_10 AC 319 ms
71,716 KB
testcase_11 AC 310 ms
71,392 KB
testcase_12 AC 316 ms
71,128 KB
testcase_13 AC 225 ms
63,348 KB
testcase_14 AC 310 ms
71,160 KB
testcase_15 AC 43 ms
49,268 KB
testcase_16 AC 43 ms
49,244 KB
testcase_17 AC 316 ms
71,792 KB
testcase_18 AC 321 ms
71,084 KB
testcase_19 AC 320 ms
71,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        String s[]=bu.readLine().split(" ");
        int a[]=new int[n],i;
        for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);

        long p[]=new long[n+1],M=(int)1e9+7;
        p[0]=1;
        for(i=1;i<=n;i++) p[i]=p[i-1]*3%M;

        long ans=0,psum=1,cur;
        for(i=0;i<n;i++)
        {
            cur=psum*a[i]%M;
            //System.out.print(cur+" "+(p[n-2-i]*2%M)+" ");
            if(i!=n-1) cur=cur*p[n-2-i]%M*2%M;
            ans=(ans+cur)%M;
            //System.out.println(cur);
            psum=psum*a[i]%M;
        }
        System.out.println(ans);
    }
}
0