結果

問題 No.2111 Sum of Diff
ユーザー tentententen
提出日時 2023-03-02 17:36:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 1,934 bytes
コンパイル時間 2,652 ms
コンパイル使用メモリ 90,944 KB
実行使用メモリ 64,528 KB
最終ジャッジ日時 2023-10-17 14:01:30
合計ジャッジ時間 11,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,456 KB
testcase_01 AC 53 ms
53,492 KB
testcase_02 AC 356 ms
63,732 KB
testcase_03 AC 320 ms
60,804 KB
testcase_04 AC 198 ms
58,812 KB
testcase_05 AC 345 ms
63,364 KB
testcase_06 AC 355 ms
63,508 KB
testcase_07 AC 216 ms
58,448 KB
testcase_08 AC 259 ms
59,024 KB
testcase_09 AC 133 ms
55,572 KB
testcase_10 AC 156 ms
55,624 KB
testcase_11 AC 299 ms
57,024 KB
testcase_12 AC 285 ms
58,652 KB
testcase_13 AC 254 ms
58,844 KB
testcase_14 AC 340 ms
61,372 KB
testcase_15 AC 348 ms
64,528 KB
testcase_16 AC 263 ms
58,836 KB
testcase_17 AC 350 ms
64,380 KB
testcase_18 AC 252 ms
58,628 KB
testcase_19 AC 318 ms
60,804 KB
testcase_20 AC 349 ms
63,528 KB
testcase_21 AC 97 ms
55,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += (pow(2, n - i - 1) - pow(2, i) + MOD) % MOD * sc.nextInt() % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0