結果

問題 No.2055 12x34...
ユーザー ks2mks2m
提出日時 2022-08-21 13:04:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 675 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 78,856 KB
実行使用メモリ 81,320 KB
最終ジャッジ日時 2024-04-18 12:47:40
合計ジャッジ時間 19,806 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,760 KB
testcase_01 AC 53 ms
37,060 KB
testcase_02 AC 137 ms
45,604 KB
testcase_03 AC 215 ms
51,060 KB
testcase_04 AC 277 ms
56,768 KB
testcase_05 AC 290 ms
57,976 KB
testcase_06 AC 258 ms
56,264 KB
testcase_07 AC 206 ms
51,408 KB
testcase_08 AC 209 ms
46,416 KB
testcase_09 AC 320 ms
60,020 KB
testcase_10 AC 311 ms
60,728 KB
testcase_11 AC 175 ms
45,944 KB
testcase_12 AC 430 ms
57,772 KB
testcase_13 AC 675 ms
68,256 KB
testcase_14 AC 326 ms
53,560 KB
testcase_15 AC 310 ms
53,688 KB
testcase_16 AC 675 ms
67,204 KB
testcase_17 AC 280 ms
53,556 KB
testcase_18 AC 527 ms
65,640 KB
testcase_19 AC 206 ms
47,940 KB
testcase_20 AC 149 ms
43,988 KB
testcase_21 AC 201 ms
47,876 KB
testcase_22 AC 471 ms
62,244 KB
testcase_23 AC 533 ms
69,144 KB
testcase_24 AC 527 ms
81,320 KB
testcase_25 AC 523 ms
69,632 KB
testcase_26 AC 551 ms
74,168 KB
testcase_27 AC 507 ms
79,800 KB
testcase_28 AC 553 ms
78,124 KB
testcase_29 AC 538 ms
79,416 KB
testcase_30 AC 510 ms
75,624 KB
testcase_31 AC 537 ms
68,476 KB
testcase_32 AC 516 ms
78,632 KB
testcase_33 AC 368 ms
63,904 KB
testcase_34 AC 393 ms
63,960 KB
testcase_35 AC 391 ms
63,740 KB
testcase_36 AC 390 ms
63,668 KB
testcase_37 AC 398 ms
64,496 KB
testcase_38 AC 391 ms
63,788 KB
testcase_39 AC 391 ms
63,952 KB
testcase_40 AC 393 ms
63,900 KB
testcase_41 AC 389 ms
63,928 KB
testcase_42 AC 390 ms
64,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 998244353;
		Map<Integer, Long> dp = new HashMap<>();
		Map<Integer, Long> val = new HashMap<>();
		for (int i = 0; i < n; i++) {
			long d1 = dp.getOrDefault(a[i], 0L);
			long d2 = dp.getOrDefault(a[i] - 1, 0L);
			long v1 = val.getOrDefault(a[i], 0L);
			long v2 = val.getOrDefault(a[i] - 1, 0L);
			dp.put(a[i], (d1 + d2 + v2) % mod);
			val.put(a[i], v1 + 1);
		}

		long ans = 0;
		for (long v : dp.values()) {
			ans += v;
		}
		ans %= mod;
		System.out.println(ans);
	}
}
0