結果
問題 | No.1170 Never Want to Walk |
ユーザー | noritake |
提出日時 | 2020-08-14 23:12:49 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,852 bytes |
コンパイル時間 | 1,937 ms |
コンパイル使用メモリ | 172,060 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-10-10 16:38:04 |
合計ジャッジ時間 | 7,558 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 339 ms
6,400 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
#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; if (uni.size(i) != 1) continue; 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++) { if (!uni.isUnite(i, j - 1)) 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; } }