結果

問題 No.2111 Sum of Diff
ユーザー shojin_proshojin_pro
提出日時 2022-10-28 22:17:17
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,077 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 2,832 ms
コンパイル使用メモリ 73,808 KB
実行使用メモリ 68,456 KB
最終ジャッジ日時 2023-09-20 05:19:11
合計ジャッジ時間 18,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,692 KB
testcase_01 AC 127 ms
55,832 KB
testcase_02 AC 1,021 ms
68,456 KB
testcase_03 AC 892 ms
64,424 KB
testcase_04 AC 425 ms
60,272 KB
testcase_05 AC 1,077 ms
66,492 KB
testcase_06 AC 1,023 ms
66,948 KB
testcase_07 AC 579 ms
60,876 KB
testcase_08 AC 624 ms
62,504 KB
testcase_09 AC 340 ms
60,240 KB
testcase_10 AC 371 ms
60,216 KB
testcase_11 AC 758 ms
64,660 KB
testcase_12 AC 763 ms
64,824 KB
testcase_13 AC 608 ms
61,364 KB
testcase_14 AC 957 ms
64,852 KB
testcase_15 AC 1,041 ms
67,372 KB
testcase_16 AC 717 ms
64,788 KB
testcase_17 AC 1,053 ms
66,672 KB
testcase_18 AC 605 ms
61,092 KB
testcase_19 AC 911 ms
64,608 KB
testcase_20 AC 1,048 ms
66,552 KB
testcase_21 AC 221 ms
58,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long mod = 998244353;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long ans = 0;
        for(int i = 0; i < n; i++){
            long cntL = rep2(2,i,mod);
            long cntR = rep2(2,n-1-i,mod);
            cntL = (cntL+mod-1) % mod;
            cntR = (cntR+mod-1) % mod;
            ans += (a[i]*cntR) % mod;
            ans %= mod;
            ans -= (a[i]*cntL) % mod;
            if(ans < 0) ans += mod;
        }
        System.out.println(ans);
    }
    
    private static long rep2(long b, long n, long mod){
        if(n == 0) return 1;
        long bn = rep2(b,n/2,mod);
        if(n % 2 == 0){
            return (bn*bn)%mod;
        }else{
            return (bn*bn)%mod*b%mod;
        }
    }
}
0