結果

問題 No.1110 好きな歌
ユーザー tentententen
提出日時 2020-10-15 16:22:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,263 ms / 5,000 ms
コード長 913 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 74,308 KB
実行使用メモリ 58,872 KB
最終ジャッジ日時 2023-09-28 01:11:30
合計ジャッジ時間 39,567 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
39,256 KB
testcase_01 AC 119 ms
39,276 KB
testcase_02 AC 118 ms
39,708 KB
testcase_03 AC 121 ms
39,624 KB
testcase_04 AC 120 ms
39,732 KB
testcase_05 AC 119 ms
39,508 KB
testcase_06 AC 113 ms
39,380 KB
testcase_07 AC 113 ms
39,172 KB
testcase_08 AC 112 ms
39,388 KB
testcase_09 AC 115 ms
39,360 KB
testcase_10 AC 115 ms
39,528 KB
testcase_11 AC 115 ms
39,136 KB
testcase_12 AC 112 ms
39,132 KB
testcase_13 AC 112 ms
39,336 KB
testcase_14 AC 169 ms
40,024 KB
testcase_15 AC 151 ms
39,752 KB
testcase_16 AC 165 ms
40,000 KB
testcase_17 AC 176 ms
40,884 KB
testcase_18 AC 134 ms
39,768 KB
testcase_19 AC 192 ms
41,008 KB
testcase_20 AC 176 ms
41,044 KB
testcase_21 AC 175 ms
40,336 KB
testcase_22 AC 177 ms
40,412 KB
testcase_23 AC 143 ms
39,732 KB
testcase_24 AC 821 ms
52,484 KB
testcase_25 AC 919 ms
54,512 KB
testcase_26 AC 633 ms
48,856 KB
testcase_27 AC 956 ms
54,284 KB
testcase_28 AC 686 ms
50,320 KB
testcase_29 AC 1,014 ms
55,604 KB
testcase_30 AC 671 ms
48,668 KB
testcase_31 AC 568 ms
47,480 KB
testcase_32 AC 1,054 ms
57,032 KB
testcase_33 AC 713 ms
52,816 KB
testcase_34 AC 847 ms
52,720 KB
testcase_35 AC 1,101 ms
55,864 KB
testcase_36 AC 385 ms
46,220 KB
testcase_37 AC 589 ms
47,484 KB
testcase_38 AC 978 ms
56,380 KB
testcase_39 AC 849 ms
52,976 KB
testcase_40 AC 985 ms
54,304 KB
testcase_41 AC 322 ms
45,848 KB
testcase_42 AC 1,080 ms
55,404 KB
testcase_43 AC 981 ms
58,060 KB
testcase_44 AC 1,109 ms
57,428 KB
testcase_45 AC 1,172 ms
56,712 KB
testcase_46 AC 1,158 ms
57,360 KB
testcase_47 AC 1,113 ms
58,388 KB
testcase_48 AC 1,198 ms
57,268 KB
testcase_49 AC 1,106 ms
56,256 KB
testcase_50 AC 1,200 ms
57,440 KB
testcase_51 AC 1,185 ms
56,764 KB
testcase_52 AC 1,186 ms
57,492 KB
testcase_53 AC 1,263 ms
58,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		Tune[] arr = new Tune[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = new Tune(i, sc.nextInt());
		}
		Arrays.sort(arr);
		int[] ans = new int[n];
		int left = 0;
		for (int i = 0; i < n; i++) {
		    while (arr[i].value - arr[left].value >= d) {
		        left++;
		    }
		    ans[arr[i].idx] = left;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    sb.append(ans[i]).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Tune implements Comparable<Tune> {
	    int idx;
	    int value;
	    
	    public Tune(int idx, int value) {
	        this.idx = idx;
	        this.value = value;
	    }
	    
	    public int compareTo(Tune another) {
	        return value - another.value;
	    }
	}
	
}
0