結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
|
提出日時 | 2021-05-10 04:18:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,482 bytes |
コンパイル時間 | 1,809 ms |
コンパイル使用メモリ | 193,856 KB |
最終ジャッジ日時 | 2025-01-21 09:43:05 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 WA * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; int uf[200005]; int x[200005]; int find(int x) { if (uf[x] < 0) { return x; } return uf[x] = find(uf[x]); } bool merge(int x, int y) { x = find(x); y = find(y); if (x == y) { return false; } uf[x] += uf[y]; uf[y] = x; return true; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); memset(uf, -1, sizeof(uf)); int N, A, B, t; cin >> N >> A >> B; for (int i = 1; i <= N; i++) { cin >> x[i]; } memset(uf, -1, sizeof(uf)); int L = 1; int R = 1; while (1) { if (L >= N && R >= N) { break; } //cout << L << ' ' << R << ' ' << x[R] - x[L] << '\n'; if (R >= N) { if (x[R] - x[L] >= A && x[R] - x[L] <= B) { merge(L, R); } L++; } else { if (x[R] - x[L] > B) { L++; } else { if (x[R] - x[L] >= A && x[R] - x[L] <= B) { //cout << L << ' ' << R << '\n'; merge(L, R); } R++; } } } L = N; R = N; while (1) { if (L <= 1 && R <= 1) { break; } //cout << L << ' ' << R << ' ' << x[R] - x[L] << '\n'; if (L<=1) { if (x[R] - x[L] >= A && x[R] - x[L] <= B) { merge(L, R); } R--; } else { if (x[R] - x[L] > B) { R--; } else { if (x[R] - x[L] >= A && x[R] - x[L] <= B) { //cout << L << ' ' << R << '\n'; merge(L, R); } L--; } } } for (int i = 1; i <= N; i++) { int R = find(i); cout << abs(uf[R]) << '\n'; } return 0; }