結果
| 問題 |
No.1645 AB's abs
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-08-16 14:54:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,452 bytes |
| コンパイル時間 | 2,314 ms |
| コンパイル使用メモリ | 77,728 KB |
| 実行使用メモリ | 60,356 KB |
| 最終ジャッジ日時 | 2024-10-09 11:47:09 |
| 合計ジャッジ時間 | 6,782 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 26 |
ソースコード
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;
int[][] dp = new int[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] += dp[i - 1][j];
}
}
}
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();
}
}
tenten