結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 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,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 201 ms
4,376 KB
testcase_25 AC 239 ms
4,696 KB
testcase_26 AC 121 ms
4,376 KB
testcase_27 AC 236 ms
4,784 KB
testcase_28 AC 137 ms
4,376 KB
testcase_29 AC 280 ms
4,736 KB
testcase_30 AC 136 ms
4,380 KB
testcase_31 AC 84 ms
4,376 KB
testcase_32 AC 313 ms
4,840 KB
testcase_33 AC 154 ms
4,376 KB
testcase_34 AC 210 ms
4,380 KB
testcase_35 AC 322 ms
5,012 KB
testcase_36 AC 36 ms
4,380 KB
testcase_37 AC 93 ms
4,376 KB
testcase_38 AC 270 ms
4,700 KB
testcase_39 AC 200 ms
4,380 KB
testcase_40 AC 252 ms
4,804 KB
testcase_41 AC 21 ms
4,380 KB
testcase_42 AC 306 ms
4,732 KB
testcase_43 AC 277 ms
4,800 KB
testcase_44 AC 326 ms
4,956 KB
testcase_45 AC 344 ms
4,916 KB
testcase_46 AC 336 ms
4,844 KB
testcase_47 AC 340 ms
4,936 KB
testcase_48 AC 336 ms
4,908 KB
testcase_49 AC 326 ms
5,040 KB
testcase_50 AC 335 ms
4,852 KB
testcase_51 AC 335 ms
5,048 KB
testcase_52 AC 341 ms
4,956 KB
testcase_53 AC 344 ms
5,012 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の個数を数える
    // "v[i]-d+1"の"+1"が重要。二分探索で良い感じに個数が求まる
    // lower_boundのほうが簡単に書けるみたい
    for(int i = 0; i < n; ++i) {
        cout << binary_search(v[i]-d+1) << endl;
    }

    return 0;
}
0