結果

問題 No.1110 好きな歌
ユーザー tentententen
提出日時 2022-08-04 14:53:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 685 ms / 5,000 ms
コード長 1,835 bytes
コンパイル時間 2,832 ms
コンパイル使用メモリ 74,788 KB
実行使用メモリ 65,732 KB
最終ジャッジ日時 2023-10-12 12:28:47
合計ジャッジ時間 25,525 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,684 KB
testcase_01 AC 42 ms
47,536 KB
testcase_02 AC 42 ms
49,828 KB
testcase_03 AC 42 ms
49,992 KB
testcase_04 AC 42 ms
49,572 KB
testcase_05 AC 43 ms
49,572 KB
testcase_06 AC 42 ms
50,016 KB
testcase_07 AC 42 ms
49,692 KB
testcase_08 AC 43 ms
49,596 KB
testcase_09 AC 43 ms
49,564 KB
testcase_10 AC 42 ms
49,696 KB
testcase_11 AC 43 ms
49,792 KB
testcase_12 AC 42 ms
49,992 KB
testcase_13 AC 43 ms
49,856 KB
testcase_14 AC 55 ms
50,624 KB
testcase_15 AC 50 ms
50,184 KB
testcase_16 AC 53 ms
51,224 KB
testcase_17 AC 64 ms
51,164 KB
testcase_18 AC 45 ms
49,708 KB
testcase_19 AC 74 ms
50,928 KB
testcase_20 AC 71 ms
50,808 KB
testcase_21 AC 50 ms
47,940 KB
testcase_22 AC 59 ms
51,952 KB
testcase_23 AC 48 ms
50,236 KB
testcase_24 AC 428 ms
60,628 KB
testcase_25 AC 478 ms
63,476 KB
testcase_26 AC 336 ms
60,576 KB
testcase_27 AC 476 ms
62,372 KB
testcase_28 AC 362 ms
60,840 KB
testcase_29 AC 553 ms
63,224 KB
testcase_30 AC 339 ms
61,512 KB
testcase_31 AC 261 ms
58,356 KB
testcase_32 AC 607 ms
65,732 KB
testcase_33 AC 358 ms
60,364 KB
testcase_34 AC 441 ms
62,352 KB
testcase_35 AC 567 ms
63,632 KB
testcase_36 AC 191 ms
57,388 KB
testcase_37 AC 284 ms
58,492 KB
testcase_38 AC 534 ms
62,980 KB
testcase_39 AC 441 ms
62,932 KB
testcase_40 AC 500 ms
62,364 KB
testcase_41 AC 156 ms
55,272 KB
testcase_42 AC 565 ms
62,784 KB
testcase_43 AC 537 ms
63,856 KB
testcase_44 AC 619 ms
65,256 KB
testcase_45 AC 605 ms
65,568 KB
testcase_46 AC 605 ms
64,900 KB
testcase_47 AC 620 ms
65,628 KB
testcase_48 AC 608 ms
65,068 KB
testcase_49 AC 607 ms
62,840 KB
testcase_50 AC 685 ms
65,020 KB
testcase_51 AC 638 ms
64,988 KB
testcase_52 AC 605 ms
64,800 KB
testcase_53 AC 635 ms
65,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

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

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0