結果

問題 No.2803 Bocching Star
ユーザー Urtusea
提出日時 2024-07-13 12:40:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 4,851 ms
コンパイル使用メモリ 287,540 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-07-13 12:40:11
合計ジャッジ時間 8,584 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int  = int64_t;
using uInt = uint64_t;

template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

void solve( /* Copyright by Urtusea */ )
{
    Int n, k;
    cin >> n >> k;

    vector<Int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    
    vector<int> id(n + 1);
    iota(id.begin(), id.end(), 0);
    sort(id.begin() + 1, id.end(), [&](int l, int r) {
        return a[l] < a[r];
    });

    vector<bool> vis(n + 1);
    for (int i = 1; i <= n; i++) {
        if (i != 1) {
            if (abs(a[id[i]] - a[id[i - 1]]) <= k) vis[i] = true;
        }

        if (i != n) {
            if (abs(a[id[i]] - a[id[i + 1]]) <= k) vis[i] = true;
        }
    }

    vector<int> cnt;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) cnt.emplace_back(id[i]);
    }
    sort(cnt.begin(), cnt.end());

    cout << cnt.size() << '\n';
    for (auto &x: cnt) {
        cout << x << " \n"[x == cnt.back()];
    }
}

int main(int argc, char *argv[], char *envp[])
{
    cin.tie(nullptr)->sync_with_stdio(false);

    // for (int i = 1, n = (cin >> n, n); i <= n; i++)
        solve();

    return 0;
}
0