結果

問題 No.2111 Sum of Diff
ユーザー tentententen
提出日時 2023-04-19 17:56:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 2,085 bytes
コンパイル時間 2,650 ms
コンパイル使用メモリ 88,020 KB
実行使用メモリ 50,524 KB
最終ジャッジ日時 2024-04-22 19:07:05
合計ジャッジ時間 10,881 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
36,796 KB
testcase_01 AC 56 ms
37,020 KB
testcase_02 AC 365 ms
50,352 KB
testcase_03 AC 316 ms
46,992 KB
testcase_04 AC 213 ms
42,976 KB
testcase_05 AC 362 ms
50,456 KB
testcase_06 AC 360 ms
49,860 KB
testcase_07 AC 243 ms
44,696 KB
testcase_08 AC 268 ms
44,992 KB
testcase_09 AC 145 ms
39,736 KB
testcase_10 AC 170 ms
40,656 KB
testcase_11 AC 301 ms
45,612 KB
testcase_12 AC 290 ms
45,284 KB
testcase_13 AC 239 ms
44,444 KB
testcase_14 AC 352 ms
47,648 KB
testcase_15 AC 361 ms
49,940 KB
testcase_16 AC 297 ms
45,140 KB
testcase_17 AC 360 ms
50,524 KB
testcase_18 AC 266 ms
44,976 KB
testcase_19 AC 344 ms
46,796 KB
testcase_20 AC 361 ms
49,492 KB
testcase_21 AC 102 ms
38,776 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 plus = 0;
        long minus = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            plus += (pow(2, n - i - 1) - 1 + MOD) % MOD * x % MOD;
            plus %= MOD;
            minus += (pow(2, i) - 1 + MOD) % MOD * x % MOD;
            minus %= MOD;
        }
        System.out.println((plus - minus + MOD) % MOD);
    }
    
    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