結果

問題 No.1110 好きな歌
ユーザー kurotemkokurotemko
提出日時 2020-07-26 17:10:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 5,000 ms
コード長 1,136 bytes
コンパイル時間 2,857 ms
コンパイル使用メモリ 203,916 KB
実行使用メモリ 5,056 KB
最終ジャッジ日時 2023-09-11 03:44:45
合計ジャッジ時間 13,303 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 196 ms
4,376 KB
testcase_25 AC 241 ms
4,704 KB
testcase_26 AC 122 ms
4,376 KB
testcase_27 AC 234 ms
4,700 KB
testcase_28 AC 134 ms
4,376 KB
testcase_29 AC 277 ms
4,772 KB
testcase_30 AC 133 ms
4,380 KB
testcase_31 AC 81 ms
4,380 KB
testcase_32 AC 304 ms
4,996 KB
testcase_33 AC 151 ms
4,380 KB
testcase_34 AC 208 ms
4,388 KB
testcase_35 AC 319 ms
5,052 KB
testcase_36 AC 35 ms
4,380 KB
testcase_37 AC 92 ms
4,388 KB
testcase_38 AC 272 ms
4,840 KB
testcase_39 AC 200 ms
4,380 KB
testcase_40 AC 253 ms
4,752 KB
testcase_41 AC 21 ms
4,380 KB
testcase_42 AC 290 ms
4,836 KB
testcase_43 AC 273 ms
4,912 KB
testcase_44 AC 326 ms
4,932 KB
testcase_45 AC 332 ms
4,860 KB
testcase_46 AC 331 ms
5,000 KB
testcase_47 AC 338 ms
4,916 KB
testcase_48 AC 333 ms
4,856 KB
testcase_49 AC 314 ms
5,012 KB
testcase_50 AC 328 ms
4,864 KB
testcase_51 AC 328 ms
4,928 KB
testcase_52 AC 327 ms
5,056 KB
testcase_53 AC 333 ms
4,988 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"が重要。二分探索で良い感じに個数が求まる
    for(int i = 0; i < n; ++i) {
        cout << binary_search(v[i]-d+1) << endl;
    }
    return 0;
}
0