結果

問題 No.1170 Never Want to Walk
ユーザー milanis48663220milanis48663220
提出日時 2020-08-14 21:47:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 1,523 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 101,852 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-18 21:28:59
合計ジャッジ時間 8,321 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 431 ms
13,568 KB
testcase_28 AC 422 ms
13,440 KB
testcase_29 AC 453 ms
13,568 KB
testcase_30 AC 432 ms
13,696 KB
testcase_31 AC 431 ms
13,440 KB
testcase_32 AC 420 ms
23,040 KB
testcase_33 AC 429 ms
15,744 KB
testcase_34 AC 443 ms
23,296 KB
testcase_35 AC 461 ms
22,144 KB
testcase_36 AC 450 ms
21,120 KB
testcase_37 AC 450 ms
22,400 KB
testcase_38 AC 462 ms
23,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
typedef long long ll;
int x[200000];
map<int, int> ans;

int N, A, B;
set<int> st;

void bfs(int x){
    queue<int> que;
    vector<int> used;
    que.push(x);
    st.erase(x);
    used.push_back(x);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        // if(st.count(v) == 0) continue;
        set<int> buf;
        {
            auto pl = st.lower_bound(v-B);
            auto pr = st.upper_bound(v-A);
            for(auto i = pl; i != pr; i++){
                que.push(*i);
                buf.insert(*i);
            }
        }
        {
            auto pl = st.lower_bound(v+A);
            auto pr = st.upper_bound(v+B);
            for(auto i = pl; i != pr; i++){
                que.push(*i);
                buf.insert(*i);
            }
        }
        for(int i : buf) {
            st.erase(i);
            used.push_back(i);
        }
    }
    for(int i : used) ans[i] = used.size();
}

const int INF = 2e9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> A >> B;
    for(int i = 0; i < N; i++){
        cin >> x[i]; st.insert(x[i]);
    }
    st.insert(-INF);
    st.insert(INF);
    for(int i = 0; i < N; i++){
        if(st.count(x[i]) != 0){
            bfs(x[i]);
        }
    }
    for(int i = 0; i < N; i++){
        cout << ans[x[i]] << endl;
    }
}
0