結果

問題 No.1170 Never Want to Walk
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2020-08-14 21:50:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 2,442 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 107,896 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-18 21:35:37
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 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 1 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 2 ms
5,376 KB
testcase_11 AC 1 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 42 ms
5,504 KB
testcase_28 AC 44 ms
5,632 KB
testcase_29 AC 45 ms
5,504 KB
testcase_30 AC 43 ms
5,504 KB
testcase_31 AC 42 ms
5,632 KB
testcase_32 AC 41 ms
5,632 KB
testcase_33 AC 42 ms
5,504 KB
testcase_34 AC 42 ms
5,504 KB
testcase_35 AC 41 ms
5,632 KB
testcase_36 AC 42 ms
5,632 KB
testcase_37 AC 40 ms
5,504 KB
testcase_38 AC 43 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

class UnionFind {
public:
    int n;
    std::vector<int> par;
    UnionFind(int n) : n(n), par(n, -1) {}

    // 集合の代表を返す
    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }
    // x と y が同じ集合に属するかを判別
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    // x が属する集合の大きさを返す
    int size(int x) {
        return -par[find(x)];
    }
    // x と y を結合 (merge した場合に true を返す)
    bool unite(int x, int y) {
        int px = find(x), py = find(y);
        if (px == py) return false;
        if (par[px] > par[py]) swap(px, py);
        par[px] += par[py];
        par[py] = px;
        return true;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; ll a, b; cin >> n >> a >> b;
    vll x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    UnionFind uni(n);
    int ai = 0, bi = 0;
    for (int i = 0; i < n; i++) {
        while (ai < n && x[ai] - x[i] < a) ai++;
        if (ai < n && x[ai] - x[i] <= b) uni.unite(i, ai);
        bi = max(bi, ai);
        while (bi < n && x[bi] - x[i] <= b) {
            uni.unite(i, bi);
            bi++;
        }
    }
    for (int i = 0; i < n; i++) cout << uni.size(i) << '\n';
    return 0;
}
0