結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-06 00:09:26 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 2,187 bytes |
| コンパイル時間 | 11,001 ms |
| コンパイル使用メモリ | 169,904 KB |
| 実行使用メモリ | 218,044 KB |
| 最終ジャッジ日時 | 2025-06-06 00:09:45 |
| 合計ジャッジ時間 | 17,903 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (110 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var c = NList;
var (n, a, b) = (c[0], c[1], c[2]);
var x = NList;
var begin = 0;
var end = 0;
var pe = 0;
var uf = new UnionFindTree(n);
for (var i = 0; i < n; ++i)
{
while (begin < n && x[begin] - x[i] < a) ++begin;
while (end < n && x[end] - x[i] <= b) ++end;
if (begin < pe)
{
uf.Unite(i - 1, i);
for (var j = pe; j < end; ++j)
{
uf.Unite(i - 1, j);
}
}
else
{
for (var j = begin; j < end; ++j)
{
uf.Unite(i, j);
}
}
pe = end;
}
var ans = new int[n];
for (var i = 0; i < n; ++i) ans[i] = uf.GetSize(i);
WriteLine(string.Join("\n", ans));
}
class UnionFindTree
{
int[] roots;
public UnionFindTree(int size)
{
roots = new int[size];
for (var i = 0; i < size; ++i) roots[i] = -1;
}
public int GetRoot(int a)
{
if (roots[a] < 0) return a;
return roots[a] = GetRoot(roots[a]);
}
public bool IsSameTree(int a, int b)
{
return GetRoot(a) == GetRoot(b);
}
public bool Unite(int a, int b)
{
var x = GetRoot(a);
var y = GetRoot(b);
if (x == y) return false;
if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; }
roots[x] += roots[y];
roots[y] = x;
return true;
}
public int GetSize(int a)
{
return -roots[GetRoot(a)];
}
}
}