結果
| 問題 |
No.2843 Birthday Present Struggle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 22:02:51 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,294 bytes |
| コンパイル時間 | 7,110 ms |
| コンパイル使用メモリ | 165,056 KB |
| 実行使用メモリ | 198,404 KB |
| 最終ジャッジ日時 | 2024-08-23 22:03:05 |
| 合計ジャッジ時間 | 12,062 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 25 WA * 9 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (89 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
namespace AtCoder;
#nullable enable
using System.Numerics;
static class Extensions
{
public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}
class AtCoder
{
object? Solve()
{
var n = Int();
var ax = Int();
var ay = Int();
var bx = Int();
var by = Int();
var cx = Int();
var cy = Int();
var moves = new[]{ (-1, 0), (0, -1), (0, 1), (1, 0) };
var g = new bool[n + 2, n + 2];
for (var i = 1; i <= n; i++) for (var j = 1; j <= n; j++) g[i, j] = true;
foreach (var (i, j) in moves) g[cx + i, cy + j] = false;
var max = int.MaxValue / 2;
var dz = new int[n + 2, n + 2];
for (var i = 1; i <= n; i++) for (var j = 1; j <= n; j++) dz[i, j] = max;
dz[bx, by] = 0;
var lz = new (int, int)[n + 2, n + 2];
var q = new Queue<(int, int)>();
q.Enqueue((bx, by));
while (dz[ax, ay] == max)
{
var (x, y) = q.Dequeue();
var nd = dz[x, y] + 1;
foreach (var (dx, dy) in moves)
{
var nx = x + dx;
var ny = y + dy;
if (!g[nx, ny] || dz[nx, ny] <= nd) continue;
dz[nx, ny] = nd;
lz[nx, ny] = (x, y);
q.Enqueue((nx, ny));
}
}
var paths = new HashSet<(int, int)>();
{
var (x, y) = (ax, ay);
while ((x, y) != (bx, by))
{
paths.Add((x, y));
(x, y) = lz[x, y];
}
paths.Add((x, y));
}
var ans = new HashSet<(int, int)>();
foreach (var (x, y) in paths)
{
foreach (var (i, j) in moves)
{
var nx = x + i;
var ny = y + j;
if (Math.Min(nx, ny) == 0 || Math.Max(nx, ny) == n + 1 || paths.Contains((nx, ny))) continue;
ans.Add((nx, ny));
}
}
Out(ans.Count);
foreach (var (x, y) in ans) Out(x + " " + y);
return null;
}
public static void Main() => new AtCoder().Run();
public void Run()
{
var res = Solve();
if (res != null)
{
if (res is bool yes) res = yes ? "Yes" : "No";
sw.WriteLine(res);
}
sw.Flush();
}
string[] input = Array.Empty<string>();
int iter = 0;
readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };
string String()
{
while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
return input[iter++];
}
T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
int Int() => Input<int>();
void Out(object? x, string? separator = null)
{
separator ??= Environment.NewLine;
if (x is System.Collections.IEnumerable obj and not string)
{
var firstLine = true;
foreach (var item in obj)
{
if (!firstLine) sw.Write(separator);
firstLine = false;
sw.Write(item);
}
}
else sw.Write(x);
sw.WriteLine();
}
}