結果

問題 No.1110 好きな歌
ユーザー ks2mks2m
提出日時 2020-07-10 21:42:40
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,127 ms / 5,000 ms
コード長 998 bytes
コンパイル時間 4,216 ms
コンパイル使用メモリ 80,648 KB
実行使用メモリ 65,360 KB
最終ジャッジ日時 2023-08-01 17:18:02
合計ジャッジ時間 34,267 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
49,988 KB
testcase_01 AC 53 ms
49,952 KB
testcase_02 AC 53 ms
50,300 KB
testcase_03 AC 52 ms
49,824 KB
testcase_04 AC 53 ms
49,868 KB
testcase_05 AC 53 ms
49,864 KB
testcase_06 AC 52 ms
50,036 KB
testcase_07 AC 52 ms
49,820 KB
testcase_08 AC 53 ms
50,268 KB
testcase_09 AC 53 ms
49,764 KB
testcase_10 AC 53 ms
49,844 KB
testcase_11 AC 54 ms
49,736 KB
testcase_12 AC 52 ms
49,848 KB
testcase_13 AC 53 ms
49,672 KB
testcase_14 AC 80 ms
51,476 KB
testcase_15 AC 65 ms
50,644 KB
testcase_16 AC 70 ms
51,584 KB
testcase_17 AC 74 ms
51,748 KB
testcase_18 AC 55 ms
49,936 KB
testcase_19 AC 88 ms
51,844 KB
testcase_20 AC 76 ms
51,808 KB
testcase_21 AC 67 ms
51,600 KB
testcase_22 AC 75 ms
51,992 KB
testcase_23 AC 65 ms
51,640 KB
testcase_24 AC 649 ms
62,812 KB
testcase_25 AC 797 ms
64,448 KB
testcase_26 AC 446 ms
60,052 KB
testcase_27 AC 817 ms
64,756 KB
testcase_28 AC 487 ms
61,944 KB
testcase_29 AC 946 ms
64,888 KB
testcase_30 AC 493 ms
62,472 KB
testcase_31 AC 333 ms
58,292 KB
testcase_32 AC 1,002 ms
65,076 KB
testcase_33 AC 529 ms
62,328 KB
testcase_34 AC 693 ms
62,264 KB
testcase_35 AC 1,038 ms
64,572 KB
testcase_36 AC 220 ms
56,720 KB
testcase_37 AC 377 ms
58,716 KB
testcase_38 AC 946 ms
64,884 KB
testcase_39 AC 651 ms
62,168 KB
testcase_40 AC 865 ms
64,552 KB
testcase_41 AC 179 ms
56,336 KB
testcase_42 AC 1,027 ms
65,020 KB
testcase_43 AC 908 ms
64,804 KB
testcase_44 AC 1,127 ms
65,232 KB
testcase_45 AC 1,043 ms
64,880 KB
testcase_46 AC 1,047 ms
64,628 KB
testcase_47 AC 1,105 ms
64,844 KB
testcase_48 AC 997 ms
65,032 KB
testcase_49 AC 1,125 ms
64,876 KB
testcase_50 AC 1,118 ms
65,360 KB
testcase_51 AC 1,073 ms
65,032 KB
testcase_52 AC 1,093 ms
64,808 KB
testcase_53 AC 1,095 ms
65,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

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]);
		int d = Integer.parseInt(sa[1]);
		Obj[] arr = new Obj[n];
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			o.a = Integer.parseInt(br.readLine());
			o.i = i;
			arr[i] = o;
		}
		br.close();

		Arrays.sort(arr, (o1, o2) -> o2.a - o1.a);
		int j = 1;
		for (int i = 0; i < n; i++) {
			while (j < n && arr[i].a - arr[j].a < d) {
				j++;
			}
			if (j < n && arr[i].a - arr[j].a >= d) {
				arr[i].ans = n - j;
			}
		}

		Arrays.sort(arr, (o1, o2) -> o1.i - o2.i);
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; i++) {
			pw.println(arr[i].ans);
		}
		pw.flush();
	}

	static class Obj {
		int a, i, ans;
	}
}
0