結果
問題 |
No.1110 好きな歌
|
ユーザー |
|
提出日時 | 2020-07-26 17:06:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,010 ms / 5,000 ms |
コード長 | 1,070 bytes |
コンパイル時間 | 4,143 ms |
コンパイル使用メモリ | 197,496 KB |
最終ジャッジ日時 | 2025-01-12 06:05:41 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d", &a); | ~~~~~^~~~~~~~~~
ソースコード
#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; }