結果

問題 No.1170 Never Want to Walk
ユーザー MisterMister
提出日時 2020-08-14 22:12:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 97,600 KB
実行使用メモリ 24,748 KB
最終ジャッジ日時 2024-04-18 22:03:14
合計ジャッジ時間 5,145 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 183 ms
22,272 KB
testcase_28 AC 181 ms
21,888 KB
testcase_29 AC 195 ms
22,528 KB
testcase_30 AC 187 ms
22,528 KB
testcase_31 AC 186 ms
22,016 KB
testcase_32 AC 169 ms
24,060 KB
testcase_33 AC 185 ms
23,336 KB
testcase_34 AC 177 ms
24,400 KB
testcase_35 AC 170 ms
24,284 KB
testcase_36 AC 165 ms
23,876 KB
testcase_37 AC 177 ms
23,968 KB
testcase_38 AC 174 ms
24,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <queue>

void solve() {
    int n, a, b;
    std::cin >> n >> a >> b;

    std::set<int> xs;
    std::map<int, int> xrev;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        xs.insert(x);
        xrev[x] = i;
    }

    std::vector<int> ans(n, -1);

    while (!xs.empty()) {
        std::vector<int> g;

        std::queue<int> que;
        que.push(*xs.begin());
        xs.erase(xs.begin());

        while (!que.empty()) {
            int x = que.front();
            que.pop();
            g.push_back(x);

            {
                int l = x - b, r = x - a;
                auto it = xs.lower_bound(l);
                while (it != xs.end() && *it <= r) {
                    que.push(*it);
                    it = xs.erase(it);
                }
            }

            {
                int l = x + a, r = x + b;
                auto it = xs.lower_bound(l);
                while (it != xs.end() && *it <= r) {
                    que.push(*it);
                    it = xs.erase(it);
                }
            }
        }

        for (auto x : g) {
            ans[xrev[x]] = g.size();
        }
    }

    for (auto a : ans) std::cout << a << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0