結果
| 問題 | No.8063 幅優先探索 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-20 23:33:12 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 2,000 ms |
| コード長 | 1,732 bytes |
| コンパイル時間 | 11,214 ms |
| コンパイル使用メモリ | 169,244 KB |
| 実行使用メモリ | 188,448 KB |
| 最終ジャッジ日時 | 2025-11-20 23:33:25 |
| 合計ジャッジ時間 | 8,961 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (135 ミリ秒)。 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;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics.X86;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var c = NList;
var (h, w) = (c[0], c[1]);
c = NList;
var (si, sj) = (c[0] - 1, c[1] - 1);
c = NList;
var (gi, gj) = (c[0] - 1, c[1] - 1);
var s = SList(h);
var mx = new int[] { -1 , 1, 0, 0 };
var my = new int[] { 0, 0, -1, 1 };
var INF = int.MaxValue / 2;
var len = new int[h][];
for (var i = 0; i < h; ++i) len[i] = Enumerable.Repeat(INF, w).ToArray();
len[si][sj] = 0;
var q = new Queue<(int i, int j)>();
q.Enqueue((si, sj));
while (q.Count > 0)
{
var cur = q.Dequeue();
if (cur.i == gi && cur.j == gj)
{
WriteLine(len[gi][gj]);
return;
}
for (var p = 0; p < 4; ++p)
{
var ni = cur.i + mx[p];
var nj = cur.j + my[p];
if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
if (len[ni][nj] <= len[cur.i][cur.j] + 1) continue;
len[ni][nj] = len[cur.i][cur.j] + 1;
q.Enqueue((ni, nj));
}
}
}
}