結果

問題 No.1170 Never Want to Walk
ユーザー noritakenoritake
提出日時 2020-08-14 23:08:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,793 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 167,296 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-18 23:01:55
合計ジャッジ時間 7,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 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 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 349 ms
6,528 KB
testcase_28 AC 338 ms
6,400 KB
testcase_29 AC 357 ms
6,528 KB
testcase_30 AC 352 ms
6,400 KB
testcase_31 AC 347 ms
6,272 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

/**
 * UnionFind(重みなし)
 */
class UnionFind
{
    private:
        vector<long long> parents;

    public:
        UnionFind(long long N)
        {
            this->parents = vector<long long>(N, -1);
        }

        long long size(long long A)
        {
            return -1 * parents[this->root(A)];
        }

        long long root(long long A)
        {
            if (this->parents[A] < 0) return A;

            this->parents[A] = this->root(this->parents[A]);
            return this->parents[A];
        }

        bool unite(long long A, long long B)
        {
            long long ra = this->root(A);
            long long rb = this->root(B);

            if (ra == rb) return false;

            if (this->size(ra) > this->size(rb)) {
                this->parents[ra] += this->parents[rb];
                this->parents[rb] = ra;
            } else {
                this->parents[rb] += this->parents[ra];
                this->parents[ra] = rb;
            }
            return true;
        }

        bool isUnite(long long A, long long B)
        {
            return this->root(A) == this->root(B);
        }

        void show()
        {
            for (int i = 0; i < this->parents.size(); i++) {
                this->root(i); // 親の更新を行う
                cout << "i: " << i << ", parents[i]: " << this->parents[i] << endl;
            }
        }
};

int main() {
    ll N, A, B; cin >> N >> A >> B;

    vl X(N + 2); rep(i, N) cin >> X[i + 1];
    X[0] = 0; X[N + 1] = LINF;

    UnionFind uni(N);

    for (int i = 0; i < N; i++) {
        int l = i;
        int r = N + 2;

        while (r - l >= 1) {
            int mid = (l + r) / 2;
            ll d = X[mid] - X[i + 1];
            if (d >= A) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        int ra = r;

        l = i; r = N + 2;
        while (r - l >= 1) {
            int mid = (l + r) / 2;
            ll d = X[mid] - X[i + 1];
            if (d > B) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        int rb = r;

        for (ll j = ra; j < rb; j++) {
            uni.unite(i, j - 1);
        }
        // cout << "i: " << (i + 1) << ", X[i]: " << X[i + 1] << ", ra: " << ra << ", X[ra]: " << X[ra] << ", rb: " << rb << ", X[rb]: " << X[rb] << endl;
        // cout << endl;
    }
// uni.show();
    for (ll i = 0; i < N; i++) {
        cout << uni.size(i) << endl;
    }
}
0