結果

問題 No.711 競技レーティング単調増加
ユーザー 37zigen37zigen
提出日時 2018-06-30 01:31:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,091 ms / 2,000 ms
コード長 1,819 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 76,908 KB
実行使用メモリ 74,636 KB
最終ジャッジ日時 2023-09-13 16:06:02
合計ジャッジ時間 26,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,000 KB
testcase_01 AC 128 ms
57,584 KB
testcase_02 AC 125 ms
55,460 KB
testcase_03 AC 134 ms
55,948 KB
testcase_04 AC 134 ms
55,784 KB
testcase_05 AC 134 ms
55,484 KB
testcase_06 AC 133 ms
55,984 KB
testcase_07 AC 134 ms
55,512 KB
testcase_08 AC 134 ms
55,740 KB
testcase_09 AC 133 ms
55,496 KB
testcase_10 AC 134 ms
55,592 KB
testcase_11 AC 134 ms
55,488 KB
testcase_12 AC 135 ms
55,708 KB
testcase_13 AC 132 ms
55,628 KB
testcase_14 AC 132 ms
55,416 KB
testcase_15 AC 134 ms
55,848 KB
testcase_16 AC 138 ms
55,584 KB
testcase_17 AC 134 ms
55,856 KB
testcase_18 AC 791 ms
65,380 KB
testcase_19 AC 791 ms
67,224 KB
testcase_20 AC 787 ms
68,048 KB
testcase_21 AC 820 ms
65,560 KB
testcase_22 AC 786 ms
66,912 KB
testcase_23 AC 837 ms
64,516 KB
testcase_24 AC 841 ms
66,840 KB
testcase_25 AC 758 ms
65,000 KB
testcase_26 AC 826 ms
64,768 KB
testcase_27 AC 766 ms
66,624 KB
testcase_28 AC 604 ms
64,848 KB
testcase_29 AC 649 ms
64,788 KB
testcase_30 AC 946 ms
71,488 KB
testcase_31 AC 1,066 ms
72,180 KB
testcase_32 AC 1,091 ms
68,764 KB
testcase_33 AC 833 ms
69,220 KB
testcase_34 AC 757 ms
69,816 KB
testcase_35 AC 872 ms
71,636 KB
testcase_36 AC 589 ms
65,572 KB
testcase_37 AC 851 ms
70,188 KB
testcase_38 AC 780 ms
74,636 KB
testcase_39 AC 543 ms
58,696 KB
testcase_40 AC 690 ms
65,776 KB
testcase_41 AC 122 ms
55,716 KB
testcase_42 AC 584 ms
62,652 KB
testcase_43 AC 661 ms
67,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		int p = 0;
		int[] A = new int[N];
		for (int i = 0; i < N; ++i) {
			int a = sc.nextInt() - i;
			if (a <= 0)
				continue;
			A[p++] = a;
		}
		A = Arrays.copyOf(A, p);
		A = shrink(A);
		int[] dp = new int[N + 1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		for (int i = 0; i < A.length; ++i) {
			// int idx = Arrays.binarySearch(dp, A[i]);
			// if (idx >= 0) {
			// dp[idx + 1] = A[i];
			// } else {
			// idx = -(idx + 1);
			// dp[idx] = A[i];
			// }
			dp[gt(dp, A[i])] = A[i];
		}
		int ans = 0;
		for (int i = 0; i < dp.length; ++i) {
			if (dp[i] >= Integer.MAX_VALUE)
				continue;
			ans = Math.max(ans, i + 1);
		}
		System.out.println(N - ans);

	}

	int[] shrink(int[] a) {
		int n = a.length;
		int[] ret = new int[n];
		int[][] x = new int[n][2];
		for (int i = 0; i < n; ++i) {
			x[i][0] = i;
			x[i][1] = a[i];
		}
		Arrays.sort(x, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Long.compare(o1[1], o2[1]);
			}
		});
		int p = 0;
		for (int i = 0; i < n; ++i) {
			ret[(int) x[i][0]] = p;
			if (i + 1 < n && x[i][1] != x[i + 1][1])
				++p;
		}
		return ret;
	}

	int gt(int[] A, int key) {
		int ok = A.length;
		int ng = -1;
		while (ok - ng > 1) {
			int m = (ok + ng) / 2;
			if (A[m] <= key) {
				ng = m;
			} else {
				ok = m;
			}
		}
		return ng + 1;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0