結果

問題 No.1170 Never Want to Walk
ユーザー snrnsidysnrnsidy
提出日時 2021-05-10 04:18:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 2,941 ms
コンパイル使用メモリ 202,140 KB
実行使用メモリ 5,224 KB
最終ジャッジ日時 2023-10-19 12:02:25
合計ジャッジ時間 7,304 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,416 KB
testcase_01 AC 3 ms
4,416 KB
testcase_02 AC 3 ms
4,416 KB
testcase_03 AC 2 ms
4,416 KB
testcase_04 AC 3 ms
4,416 KB
testcase_05 AC 2 ms
4,416 KB
testcase_06 AC 3 ms
4,416 KB
testcase_07 AC 2 ms
4,416 KB
testcase_08 AC 2 ms
4,416 KB
testcase_09 AC 3 ms
4,416 KB
testcase_10 AC 3 ms
4,416 KB
testcase_11 AC 2 ms
4,416 KB
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 AC 2 ms
4,428 KB
testcase_23 AC 2 ms
4,428 KB
testcase_24 AC 2 ms
4,428 KB
testcase_25 AC 3 ms
4,428 KB
testcase_26 AC 3 ms
4,428 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 41 ms
5,176 KB
testcase_33 AC 42 ms
5,164 KB
testcase_34 AC 42 ms
5,192 KB
testcase_35 AC 41 ms
5,188 KB
testcase_36 AC 41 ms
5,168 KB
testcase_37 AC 42 ms
5,172 KB
testcase_38 AC 43 ms
5,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0