結果

問題 No.1268 Fruit Rush 2
ユーザー ks2mks2m
提出日時 2020-10-24 00:01:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 816 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 4,476 ms
コンパイル使用メモリ 74,904 KB
実行使用メモリ 86,744 KB
最終ジャッジ日時 2023-09-28 19:22:21
合計ジャッジ時間 17,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,628 KB
testcase_01 AC 45 ms
49,736 KB
testcase_02 AC 46 ms
49,996 KB
testcase_03 AC 45 ms
49,420 KB
testcase_04 AC 45 ms
49,276 KB
testcase_05 AC 44 ms
49,384 KB
testcase_06 AC 44 ms
49,476 KB
testcase_07 AC 45 ms
49,552 KB
testcase_08 AC 46 ms
49,320 KB
testcase_09 AC 45 ms
49,348 KB
testcase_10 AC 45 ms
49,784 KB
testcase_11 AC 46 ms
49,316 KB
testcase_12 AC 46 ms
49,268 KB
testcase_13 AC 45 ms
49,348 KB
testcase_14 AC 46 ms
49,476 KB
testcase_15 AC 45 ms
49,316 KB
testcase_16 AC 443 ms
67,836 KB
testcase_17 AC 382 ms
66,524 KB
testcase_18 AC 439 ms
66,756 KB
testcase_19 AC 405 ms
66,664 KB
testcase_20 AC 390 ms
66,228 KB
testcase_21 AC 382 ms
65,568 KB
testcase_22 AC 444 ms
66,920 KB
testcase_23 AC 456 ms
66,680 KB
testcase_24 AC 392 ms
66,380 KB
testcase_25 AC 397 ms
65,920 KB
testcase_26 AC 790 ms
86,744 KB
testcase_27 AC 788 ms
86,492 KB
testcase_28 AC 802 ms
86,636 KB
testcase_29 AC 816 ms
86,480 KB
testcase_30 AC 816 ms
85,972 KB
testcase_31 AC 678 ms
78,904 KB
testcase_32 AC 606 ms
77,356 KB
testcase_33 AC 456 ms
84,812 KB
testcase_34 AC 458 ms
75,812 KB
testcase_35 AC 477 ms
82,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
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(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		Arrays.sort(a);
		Map<Long, Long> map = new HashMap<>();
		for (int i = 1; i < n; i++) {
			long val = 0;
			if (a[i] - 1 == a[i - 1]) {
				val++;
			}
			val += map.getOrDefault(a[i] - 1, 0L);
			map.put(a[i] + 1, val);
		}

		long ans = n;
		for (long v : map.values()) {
			ans += v;
		}
		System.out.println(ans);
	}
}
0