結果
問題 | No.2111 Sum of Diff |
ユーザー | shojin_pro |
提出日時 | 2022-10-28 22:17:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,060 ms / 2,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 77,680 KB |
実行使用メモリ | 71,092 KB |
最終ジャッジ日時 | 2024-07-06 01:28:12 |
合計ジャッジ時間 | 17,569 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
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; } } }