結果
問題 |
No.1645 AB's abs
|
ユーザー |
![]() |
提出日時 | 2021-08-16 14:58:19 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 1,536 bytes |
コンパイル時間 | 2,610 ms |
コンパイル使用メモリ | 77,380 KB |
実行使用メモリ | 54,680 KB |
最終ジャッジ日時 | 2024-10-09 11:54:11 |
合計ジャッジ時間 | 7,263 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
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(); int base = n * 100; long[][] dp = new long[n + 1][base * 2 + 1]; dp[0][base] = 1; for (int i = 1; i <= n; i++) { int x = sc.nextInt(); for (int j = 0; j < dp[i].length; j++) { if (dp[i - 1][j] > 0) { dp[i][j + x] += dp[i - 1][j]; dp[i][j + x] %= MOD; dp[i][j - x] += dp[i - 1][j]; dp[i][j + x] %= MOD; } } } long ans = 0; for (int i = 0; i < dp[n].length; i++) { long value = Math.abs(i - base); ans += value * dp[n][i] % MOD; ans %= MOD; } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }