結果

問題 No.1110 好きな歌
ユーザー shojin_proshojin_pro
提出日時 2020-07-10 21:51:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,598 ms / 5,000 ms
コード長 2,591 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 79,720 KB
実行使用メモリ 64,856 KB
最終ジャッジ日時 2024-04-19 16:50:13
合計ジャッジ時間 40,783 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,560 KB
testcase_01 AC 51 ms
36,948 KB
testcase_02 AC 51 ms
37,152 KB
testcase_03 AC 49 ms
36,828 KB
testcase_04 AC 49 ms
36,980 KB
testcase_05 AC 49 ms
36,832 KB
testcase_06 AC 48 ms
36,812 KB
testcase_07 AC 48 ms
36,884 KB
testcase_08 AC 47 ms
36,988 KB
testcase_09 AC 49 ms
36,940 KB
testcase_10 AC 48 ms
36,980 KB
testcase_11 AC 48 ms
37,056 KB
testcase_12 AC 47 ms
37,176 KB
testcase_13 AC 48 ms
36,972 KB
testcase_14 AC 79 ms
37,732 KB
testcase_15 AC 76 ms
37,544 KB
testcase_16 AC 83 ms
38,016 KB
testcase_17 AC 98 ms
38,832 KB
testcase_18 AC 53 ms
36,928 KB
testcase_19 AC 100 ms
38,652 KB
testcase_20 AC 100 ms
38,344 KB
testcase_21 AC 83 ms
37,360 KB
testcase_22 AC 88 ms
38,072 KB
testcase_23 AC 72 ms
36,980 KB
testcase_24 AC 1,071 ms
60,672 KB
testcase_25 AC 1,146 ms
60,516 KB
testcase_26 AC 748 ms
57,688 KB
testcase_27 AC 1,378 ms
61,196 KB
testcase_28 AC 818 ms
58,356 KB
testcase_29 AC 1,310 ms
62,672 KB
testcase_30 AC 759 ms
58,076 KB
testcase_31 AC 569 ms
49,136 KB
testcase_32 AC 1,381 ms
63,012 KB
testcase_33 AC 838 ms
58,580 KB
testcase_34 AC 1,043 ms
61,248 KB
testcase_35 AC 1,371 ms
64,800 KB
testcase_36 AC 357 ms
46,544 KB
testcase_37 AC 642 ms
53,232 KB
testcase_38 AC 1,338 ms
60,512 KB
testcase_39 AC 1,106 ms
60,648 KB
testcase_40 AC 1,110 ms
62,108 KB
testcase_41 AC 259 ms
43,700 KB
testcase_42 AC 1,286 ms
62,796 KB
testcase_43 AC 1,284 ms
62,300 KB
testcase_44 AC 1,350 ms
64,408 KB
testcase_45 AC 1,522 ms
63,840 KB
testcase_46 AC 1,285 ms
64,608 KB
testcase_47 AC 1,598 ms
64,156 KB
testcase_48 AC 1,515 ms
64,012 KB
testcase_49 AC 1,337 ms
64,856 KB
testcase_50 AC 1,464 ms
63,900 KB
testcase_51 AC 1,455 ms
62,096 KB
testcase_52 AC 1,507 ms
59,668 KB
testcase_53 AC 1,474 ms
64,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        long[] arr = new long[n];
        ArrayList<Long> a = new ArrayList<Long>();
        for(int i = 0; i < n; i++){
            long b = sc.nextLong();
            arr[i] = b;
            a.add(b);
        }
        Collections.sort(a,Comparator.reverseOrder());
        for(int i = 0; i < n; i++){
            System.out.println(n-beamSearch(arr[i]-d,a));
        }
    }
    
    public static int beamSearch(long d, ArrayList<Long> arr){
        int left = 0;
        int right = arr.size();
        while(right - left > 1){
            int mid = (right + left) / 2;
            if(arr.get(mid) > d){
                left = mid;
            }else{
                right = mid;
            }
        }
        return right;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}
0