結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
totori_nyaa
|
| 提出日時 | 2020-10-07 20:24:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 1,509 bytes |
| コンパイル時間 | 2,377 ms |
| コンパイル使用メモリ | 198,780 KB |
| 最終ジャッジ日時 | 2025-01-15 03:17:25 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define totori signed
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};
class UnionFind{
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> parent;
UnionFind(int N){
parent = vector<int>(N,-1);
}
int root(int A){
if(parent[A] < 0) return A;
return parent[A]=root(parent[A]);
}
int size(int A){
return -parent[root(A)];
}
bool unite(int A, int B) {
A = root(A), B = root(B);
if(A == B) return false;
if(size(A) < size(B)) swap(A,B);
parent[A] += parent[B];
parent[B] = A;
return true;
}
bool same(int A, int B){
return root(A)==root(B);
}
};
totori main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int n,a,b;
cin>>n>>a>>b;
int x[n];
for(int i=0;i<n;i++)cin>>x[i];
UnionFind uni(n);
int r = 0;
for(int i=0;i<n;i++){
chmax(r,i);
if(r>i && x[r-1]-x[i]>=a && x[r-1]-x[i]>=a)uni.unite(r-1,i);
while(r<n && x[r]-x[i]<=b){
if(x[r]-x[i]>=a)uni.unite(i,r);
r++;
}
}
for(int i=0;i<n;i++){
cout << uni.size(i) << "\n";
}
}
totori_nyaa