結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
54,180 KB
testcase_01 AC 131 ms
54,284 KB
testcase_02 AC 180 ms
56,324 KB
testcase_03 AC 128 ms
53,896 KB
testcase_04 AC 128 ms
54,132 KB
testcase_05 AC 130 ms
53,960 KB
testcase_06 AC 134 ms
54,148 KB
testcase_07 AC 127 ms
54,084 KB
testcase_08 AC 190 ms
57,084 KB
testcase_09 AC 194 ms
57,164 KB
testcase_10 AC 184 ms
57,048 KB
testcase_11 AC 194 ms
56,504 KB
testcase_12 AC 187 ms
57,084 KB
testcase_13 AC 335 ms
60,052 KB
testcase_14 AC 292 ms
59,132 KB
testcase_15 AC 342 ms
61,092 KB
testcase_16 AC 329 ms
61,140 KB
testcase_17 AC 333 ms
60,304 KB
testcase_18 AC 313 ms
59,584 KB
testcase_19 AC 328 ms
61,288 KB
testcase_20 AC 303 ms
59,384 KB
testcase_21 AC 316 ms
59,492 KB
testcase_22 AC 329 ms
61,004 KB
testcase_23 AC 326 ms
60,188 KB
testcase_24 AC 335 ms
61,144 KB
testcase_25 AC 342 ms
61,440 KB
testcase_26 AC 334 ms
60,104 KB
testcase_27 AC 338 ms
61,184 KB
testcase_28 AC 328 ms
61,112 KB
testcase_29 AC 341 ms
61,152 KB
testcase_30 AC 344 ms
61,480 KB
testcase_31 AC 348 ms
61,528 KB
testcase_32 AC 347 ms
61,356 KB
testcase_33 AC 414 ms
66,448 KB
testcase_34 AC 404 ms
64,196 KB
testcase_35 AC 402 ms
64,380 KB
testcase_36 AC 412 ms
66,728 KB
testcase_37 AC 418 ms
66,116 KB
testcase_38 AC 174 ms
54,436 KB
権限があれば一括ダウンロードができます

ソースコード

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)) % mod);
				next = k - a[i];
				wk.put(next, (wk.getOrDefault(next, 0L) + map.get(k)) % mod);
			}
			map = wk;
		}
		long ans = 0;
		for (Integer k : map.keySet()) {
			long val = Math.abs(k) * map.get(k) % mod;
			ans += val;
		}
		ans %= mod;
		System.out.println(ans);
	}
}
0