結果
問題 | No.1645 AB's abs |
ユーザー | tenten |
提出日時 | 2023-04-17 17:51:06 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 2,200 bytes |
コンパイル時間 | 2,465 ms |
コンパイル使用メモリ | 90,048 KB |
実行使用メモリ | 60,792 KB |
最終ジャッジ日時 | 2024-10-12 19:27:34 |
合計ジャッジ時間 | 6,465 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
50,340 KB |
testcase_01 | AC | 52 ms
50,340 KB |
testcase_02 | AC | 59 ms
50,408 KB |
testcase_03 | AC | 54 ms
50,280 KB |
testcase_04 | AC | 53 ms
50,308 KB |
testcase_05 | AC | 52 ms
50,336 KB |
testcase_06 | AC | 52 ms
49,836 KB |
testcase_07 | AC | 53 ms
50,288 KB |
testcase_08 | AC | 71 ms
50,580 KB |
testcase_09 | AC | 65 ms
50,784 KB |
testcase_10 | AC | 63 ms
50,500 KB |
testcase_11 | AC | 63 ms
50,628 KB |
testcase_12 | AC | 62 ms
50,528 KB |
testcase_13 | AC | 86 ms
60,792 KB |
testcase_14 | AC | 85 ms
56,556 KB |
testcase_15 | AC | 84 ms
60,372 KB |
testcase_16 | AC | 84 ms
56,280 KB |
testcase_17 | AC | 87 ms
60,488 KB |
testcase_18 | AC | 84 ms
56,200 KB |
testcase_19 | AC | 85 ms
60,376 KB |
testcase_20 | AC | 81 ms
56,328 KB |
testcase_21 | AC | 82 ms
56,344 KB |
testcase_22 | AC | 85 ms
60,584 KB |
testcase_23 | AC | 87 ms
60,628 KB |
testcase_24 | AC | 85 ms
60,696 KB |
testcase_25 | AC | 85 ms
60,244 KB |
testcase_26 | AC | 85 ms
60,712 KB |
testcase_27 | AC | 86 ms
60,408 KB |
testcase_28 | AC | 85 ms
60,532 KB |
testcase_29 | AC | 84 ms
60,492 KB |
testcase_30 | AC | 84 ms
60,592 KB |
testcase_31 | AC | 85 ms
60,328 KB |
testcase_32 | AC | 84 ms
60,588 KB |
testcase_33 | AC | 86 ms
60,684 KB |
testcase_34 | AC | 85 ms
60,560 KB |
testcase_35 | AC | 87 ms
60,592 KB |
testcase_36 | AC | 85 ms
60,648 KB |
testcase_37 | AC | 85 ms
60,624 KB |
testcase_38 | AC | 87 ms
60,736 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(); } }