結果
問題 |
No.711 競技レーティング単調増加
|
ユーザー |
|
提出日時 | 2018-06-30 01:31:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,117 ms / 2,000 ms |
コード長 | 1,819 bytes |
コンパイル時間 | 2,416 ms |
コンパイル使用メモリ | 80,312 KB |
実行使用メモリ | 75,660 KB |
最終ジャッジ日時 | 2024-07-01 00:45:30 |
合計ジャッジ時間 | 29,634 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
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)); } }