結果
問題 | No.1645 AB's abs |
ユーザー |
![]() |
提出日時 | 2023-04-17 17:51:06 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 2,200 bytes |
コンパイル時間 | 2,678 ms |
コンパイル使用メモリ | 89,288 KB |
実行使用メモリ | 60,928 KB |
最終ジャッジ日時 | 2024-04-20 21:15:23 |
合計ジャッジ時間 | 7,493 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,352 KB |
testcase_01 | AC | 54 ms
50,700 KB |
testcase_02 | AC | 61 ms
50,464 KB |
testcase_03 | AC | 54 ms
50,332 KB |
testcase_04 | AC | 55 ms
50,356 KB |
testcase_05 | AC | 54 ms
50,404 KB |
testcase_06 | AC | 55 ms
50,096 KB |
testcase_07 | AC | 55 ms
50,232 KB |
testcase_08 | AC | 67 ms
50,832 KB |
testcase_09 | AC | 66 ms
50,700 KB |
testcase_10 | AC | 75 ms
50,848 KB |
testcase_11 | AC | 66 ms
50,980 KB |
testcase_12 | AC | 66 ms
50,484 KB |
testcase_13 | AC | 90 ms
60,448 KB |
testcase_14 | AC | 81 ms
56,304 KB |
testcase_15 | AC | 87 ms
60,444 KB |
testcase_16 | AC | 88 ms
56,664 KB |
testcase_17 | AC | 88 ms
60,624 KB |
testcase_18 | AC | 87 ms
56,644 KB |
testcase_19 | AC | 91 ms
60,656 KB |
testcase_20 | AC | 83 ms
56,424 KB |
testcase_21 | AC | 83 ms
56,408 KB |
testcase_22 | AC | 87 ms
60,892 KB |
testcase_23 | AC | 89 ms
60,724 KB |
testcase_24 | AC | 90 ms
60,372 KB |
testcase_25 | AC | 86 ms
60,708 KB |
testcase_26 | AC | 88 ms
60,496 KB |
testcase_27 | AC | 88 ms
60,592 KB |
testcase_28 | AC | 91 ms
60,560 KB |
testcase_29 | AC | 90 ms
60,604 KB |
testcase_30 | AC | 95 ms
60,756 KB |
testcase_31 | AC | 91 ms
60,268 KB |
testcase_32 | AC | 89 ms
60,644 KB |
testcase_33 | AC | 91 ms
60,812 KB |
testcase_34 | AC | 86 ms
60,548 KB |
testcase_35 | AC | 90 ms
60,828 KB |
testcase_36 | AC | 86 ms
60,300 KB |
testcase_37 | AC | 88 ms
60,468 KB |
testcase_38 | AC | 87 ms
60,928 KB |
ソースコード
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(); int[][] counts = new int[n + 1][n * 2 * 100 + 1]; counts[0][n * 100] = 1; for (int i = 1; i <= n; i++) { int x = sc.nextInt(); for (int j = 0; j < counts[i].length; j++) { if (counts[i - 1][j] > 0) { counts[i][j - x] += counts[i - 1][j]; counts[i][j - x] %= MOD; counts[i][j + x] += counts[i - 1][j]; counts[i][j + x] %= MOD; } } } long ans = 0; for (int i = 0; i < counts[n].length; i++) { ans += Math.abs(i - n * 100L) * counts[n][i] % MOD; ans %= MOD; } System.out.println(ans); } } 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(); } }