結果

問題 No.2335 Jump
ユーザー ks2mks2m
提出日時 2023-06-02 21:41:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 4,713 ms
コンパイル使用メモリ 74,072 KB
実行使用メモリ 67,292 KB
最終ジャッジ日時 2023-08-28 03:00:51
合計ジャッジ時間 7,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,484 KB
testcase_01 AC 43 ms
49,156 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 285 ms
66,852 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 284 ms
67,292 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

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

		long ans = 0;
		int goal = n;
		for (int i = n - 1; i >= 0; i--) {
			while (set.contains(goal)) {
				set.remove(goal);
				goal--;
			}
			if (goal == 0) {
				break;
			}
			ans += a[i] - goal - (n - set.size() - 1);
			set.add(goal);
		}
		System.out.println(ans);
	}
}
0