結果

問題 No.1110 好きな歌
ユーザー kurotemkokurotemko
提出日時 2020-07-26 17:06:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 5,000 ms
コード長 1,070 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 203,888 KB
実行使用メモリ 5,036 KB
最終ジャッジ日時 2023-09-11 03:39:35
合計ジャッジ時間 16,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 197 ms
4,380 KB
testcase_25 AC 257 ms
4,752 KB
testcase_26 AC 127 ms
4,384 KB
testcase_27 AC 236 ms
4,660 KB
testcase_28 AC 138 ms
4,380 KB
testcase_29 AC 284 ms
4,864 KB
testcase_30 AC 135 ms
4,380 KB
testcase_31 AC 83 ms
4,376 KB
testcase_32 AC 315 ms
4,844 KB
testcase_33 AC 152 ms
4,376 KB
testcase_34 AC 211 ms
4,380 KB
testcase_35 AC 330 ms
5,036 KB
testcase_36 AC 36 ms
4,380 KB
testcase_37 AC 89 ms
4,380 KB
testcase_38 AC 280 ms
4,888 KB
testcase_39 AC 203 ms
4,380 KB
testcase_40 AC 263 ms
4,832 KB
testcase_41 AC 20 ms
4,376 KB
testcase_42 AC 299 ms
4,816 KB
testcase_43 AC 274 ms
4,760 KB
testcase_44 AC 329 ms
4,896 KB
testcase_45 AC 344 ms
5,000 KB
testcase_46 AC 337 ms
4,976 KB
testcase_47 AC 341 ms
4,964 KB
testcase_48 AC 339 ms
4,936 KB
testcase_49 AC 323 ms
4,896 KB
testcase_50 AC 335 ms
4,844 KB
testcase_51 AC 332 ms
4,900 KB
testcase_52 AC 342 ms
5,000 KB
testcase_53 AC 342 ms
4,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// ソート用の配列(二分探索で使用)
vector<int> s;

// ------------------------------------------------------------
// けんちょんさんのブログを参考
// https://qiita.com/drken/items/97e37dd6143e33a64c8c
int binary_search(int key) {
    int ng = -1;
    int ok = (int)s.size();
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (s[mid] >= key) ok = mid;
        else ng = mid;
    }
    return ok;
}
// ------------------------------------------------------------

int main() {
    // 入力(入力が多いためscanfを使用)
    int n, d;
    cin >> n >> d;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        v[i] = a;
        s.emplace_back(a);
    }
    // 好感度でソート
    sort(s.begin(), s.end());
    // 曲iにおいて、曲i - 曲j >= Dである曲jの個数を数える
    for(int i = 0; i < n; ++i) {
        int k = binary_search(v[i]-d+1);
        cout << k << endl;
    }
    return 0;
}
0