結果

問題 No.2111 Sum of Diff
ユーザー tentententen
提出日時 2022-10-31 12:47:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 61,212 KB
最終ジャッジ日時 2023-09-22 10:16:18
合計ジャッジ時間 7,407 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,544 KB
testcase_01 AC 41 ms
49,360 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 first = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            sc.nextInt();
        }
        long last = sc.nextInt();
        first *= (pow(2, n - 1) - 1 + MOD) % MOD;
        first %= MOD;
        last *= (pow(2, n - 1) - 1 + MOD) % MOD;
        last %= MOD;
        System.out.println((first - last + 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 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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0