結果

問題 No.1110 好きな歌
ユーザー tentententen
提出日時 2022-10-04 15:59:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 732 ms / 5,000 ms
コード長 2,030 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 74,548 KB
実行使用メモリ 67,572 KB
最終ジャッジ日時 2023-08-28 18:01:40
合計ジャッジ時間 23,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,744 KB
testcase_01 AC 44 ms
49,952 KB
testcase_02 AC 45 ms
49,820 KB
testcase_03 AC 44 ms
49,948 KB
testcase_04 AC 45 ms
49,816 KB
testcase_05 AC 45 ms
49,588 KB
testcase_06 AC 45 ms
49,764 KB
testcase_07 AC 45 ms
47,932 KB
testcase_08 AC 45 ms
49,736 KB
testcase_09 AC 46 ms
49,732 KB
testcase_10 AC 45 ms
49,696 KB
testcase_11 AC 44 ms
49,552 KB
testcase_12 AC 44 ms
49,884 KB
testcase_13 AC 43 ms
49,684 KB
testcase_14 AC 55 ms
50,368 KB
testcase_15 AC 52 ms
49,716 KB
testcase_16 AC 56 ms
50,392 KB
testcase_17 AC 76 ms
51,544 KB
testcase_18 AC 48 ms
49,748 KB
testcase_19 AC 67 ms
52,092 KB
testcase_20 AC 64 ms
51,868 KB
testcase_21 AC 53 ms
50,164 KB
testcase_22 AC 61 ms
49,828 KB
testcase_23 AC 50 ms
50,036 KB
testcase_24 AC 438 ms
60,596 KB
testcase_25 AC 514 ms
62,992 KB
testcase_26 AC 354 ms
58,676 KB
testcase_27 AC 529 ms
62,928 KB
testcase_28 AC 373 ms
60,852 KB
testcase_29 AC 591 ms
63,364 KB
testcase_30 AC 356 ms
60,680 KB
testcase_31 AC 277 ms
58,816 KB
testcase_32 AC 620 ms
63,376 KB
testcase_33 AC 381 ms
60,860 KB
testcase_34 AC 467 ms
62,948 KB
testcase_35 AC 732 ms
63,600 KB
testcase_36 AC 199 ms
57,796 KB
testcase_37 AC 283 ms
58,412 KB
testcase_38 AC 586 ms
65,036 KB
testcase_39 AC 462 ms
62,712 KB
testcase_40 AC 540 ms
62,768 KB
testcase_41 AC 157 ms
55,336 KB
testcase_42 AC 574 ms
62,808 KB
testcase_43 AC 578 ms
64,816 KB
testcase_44 AC 655 ms
65,224 KB
testcase_45 AC 702 ms
64,480 KB
testcase_46 AC 700 ms
65,012 KB
testcase_47 AC 699 ms
67,572 KB
testcase_48 AC 663 ms
65,152 KB
testcase_49 AC 614 ms
60,536 KB
testcase_50 AC 678 ms
65,608 KB
testcase_51 AC 682 ms
64,852 KB
testcase_52 AC 718 ms
65,180 KB
testcase_53 AC 676 ms
66,572 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();
        Tune[] tunes = new Tune[n];
        for (int i = 0; i < n; i++) {
            tunes[i] = new Tune(i, sc.nextInt());
        }
        Arrays.sort(tunes);
        int[] counts = new int[n + 2];
        int right = 0;
        for (int i = 0; i < n; i++) {
            while (right < n && tunes[i].value + d > tunes[right].value) {
                right++;
            }
            counts[right + 1]++;
        }
        int[] ans = new int[n];
        for (int i = 1; i <= n; i++) {
            counts[i] += counts[i - 1];
            ans[tunes[i - 1].idx] = counts[i];
        }
        StringBuilder sb = new StringBuilder();
        for (int x : ans) {
            sb.append(x).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;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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