結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
noritake
|
| 提出日時 | 2020-08-14 23:11:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,821 bytes |
| コンパイル時間 | 1,645 ms |
| コンパイル使用メモリ | 172,828 KB |
| 実行使用メモリ | 13,092 KB |
| 最終ジャッジ日時 | 2024-10-10 16:37:33 |
| 合計ジャッジ時間 | 8,061 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 TLE * 1 -- * 6 |
ソースコード
#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++) {
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;
}
}
noritake