結果

問題 No.1645 AB's abs
ユーザー ks2mks2m
提出日時 2021-08-13 21:33:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 880 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 79,348 KB
実行使用メモリ 66,752 KB
最終ジャッジ日時 2024-04-14 16:55:46
合計ジャッジ時間 14,304 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
54,296 KB
testcase_01 AC 117 ms
52,972 KB
testcase_02 AC 184 ms
56,644 KB
testcase_03 AC 130 ms
54,844 KB
testcase_04 AC 127 ms
54,168 KB
testcase_05 AC 128 ms
54,304 KB
testcase_06 AC 131 ms
54,052 KB
testcase_07 AC 128 ms
54,180 KB
testcase_08 AC 195 ms
56,820 KB
testcase_09 AC 189 ms
56,516 KB
testcase_10 AC 190 ms
57,256 KB
testcase_11 AC 188 ms
56,780 KB
testcase_12 AC 196 ms
56,976 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int mod = 998244353;
		Map<Integer, Long> map = new HashMap<>();
		map.put(0, 1L);
		for (int i = 0; i < n; i++) {
			Map<Integer, Long> wk = new HashMap<>();
			for (Integer k : map.keySet()) {
				int next = k + a[i];
				wk.put(next, wk.getOrDefault(next, 0L) + map.get(k));
				next = k - a[i];
				wk.put(next, wk.getOrDefault(next, 0L) + map.get(k));
			}
			map = wk;
		}
		long ans = 0;
		for (Integer k : map.keySet()) {
			long v = map.get(k) % mod;
			long val = Math.abs(k) * v % mod;
			ans += val;
		}
		ans %= mod;
		System.out.println(ans);
	}
}
0