結果

問題 No.1110 好きな歌
ユーザー bluemeganebluemegane
提出日時 2020-07-11 17:03:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 240 ms / 5,000 ms
コード長 1,474 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 104,832 KB
実行使用メモリ 29,056 KB
最終ジャッジ日時 2024-04-21 07:07:34
合計ジャッジ時間 9,592 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
17,920 KB
testcase_01 AC 23 ms
17,920 KB
testcase_02 AC 24 ms
18,304 KB
testcase_03 AC 23 ms
17,792 KB
testcase_04 AC 24 ms
18,048 KB
testcase_05 AC 22 ms
18,048 KB
testcase_06 AC 23 ms
17,792 KB
testcase_07 AC 23 ms
18,048 KB
testcase_08 AC 25 ms
18,048 KB
testcase_09 AC 24 ms
18,048 KB
testcase_10 AC 24 ms
18,048 KB
testcase_11 AC 25 ms
18,304 KB
testcase_12 AC 24 ms
18,048 KB
testcase_13 AC 24 ms
18,304 KB
testcase_14 AC 25 ms
18,176 KB
testcase_15 AC 25 ms
18,176 KB
testcase_16 AC 25 ms
18,304 KB
testcase_17 AC 26 ms
18,048 KB
testcase_18 AC 24 ms
18,048 KB
testcase_19 AC 26 ms
18,048 KB
testcase_20 AC 26 ms
18,432 KB
testcase_21 AC 29 ms
18,176 KB
testcase_22 AC 27 ms
18,304 KB
testcase_23 AC 25 ms
18,304 KB
testcase_24 AC 140 ms
25,088 KB
testcase_25 AC 165 ms
25,728 KB
testcase_26 AC 103 ms
24,064 KB
testcase_27 AC 167 ms
25,984 KB
testcase_28 AC 104 ms
23,808 KB
testcase_29 AC 204 ms
27,520 KB
testcase_30 AC 92 ms
23,424 KB
testcase_31 AC 71 ms
22,272 KB
testcase_32 AC 212 ms
27,648 KB
testcase_33 AC 99 ms
23,424 KB
testcase_34 AC 139 ms
25,088 KB
testcase_35 AC 191 ms
26,112 KB
testcase_36 AC 42 ms
19,424 KB
testcase_37 AC 82 ms
23,168 KB
testcase_38 AC 196 ms
27,520 KB
testcase_39 AC 153 ms
25,856 KB
testcase_40 AC 153 ms
24,832 KB
testcase_41 AC 37 ms
18,852 KB
testcase_42 AC 183 ms
26,112 KB
testcase_43 AC 196 ms
27,136 KB
testcase_44 AC 203 ms
26,752 KB
testcase_45 AC 222 ms
27,648 KB
testcase_46 AC 209 ms
27,264 KB
testcase_47 AC 233 ms
29,056 KB
testcase_48 AC 220 ms
27,776 KB
testcase_49 AC 180 ms
25,600 KB
testcase_50 AC 224 ms
27,392 KB
testcase_51 AC 207 ms
26,880 KB
testcase_52 AC 215 ms
27,776 KB
testcase_53 AC 240 ms
28,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var d = int.Parse(line[1]);
        var a = new int[n];
        var a2 = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine().Trim());
            a2[i] = a[i];
        }
        getAns(n, d, a, a2);
    }
    static void getAns(int n, int d, int[] a, int[] a2)
    {
        Array.Sort(a);
        var ans = new int[n];
        for (int i = 0; i < n; i++)
        {
            var t = a2[i] - d;
            if (t <= 0) ans[i] = 0;
            else
            {
                var p = UpperBound(a, t);
                ans[i] = p;
            }
        }
        Console.WriteLine(string.Join("\n", ans));
    }
    static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) <= 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }

    //引数省略のオーバーロード
    public static int UpperBound<T>(T[] arr, T value)
    {
        return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }

}
0