結果

問題 No.3679 なんかでっかい虫リターンズ
コンテスト
ユーザー 鳩でもわかるC#
提出日時 2026-09-05 13:56:26
言語 C#
(.NET 10.0.400)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 41 ms / 2,000 ms
+ 735µs
コード長 3,619 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,346 ms
コンパイル使用メモリ 172,508 KB
実行使用メモリ 198,800 KB
最終ジャッジ日時 2026-09-05 13:56:59
合計ジャッジ時間 13,862 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (119 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

using System.Diagnostics;
class Program
{
    static string ReadLine() => Console.ReadLine().Trim();
    static int ReadInt() => int.Parse(ReadLine());
    static long ReadLong() => long.Parse(ReadLine());
    static int[] ReadIntArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => int.Parse(_)).ToArray() : new int[0]; }
    static long[] ReadLongArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => long.Parse(_)).ToArray() : new long[0]; }
    static (int, int) ReadInt2() { int[] vs = ReadIntArray(); return (vs[0], vs[1]); }
    static (int, int, int) ReadInt3() { int[] vs = ReadIntArray(); return (vs[0], vs[1], vs[2]); }
    static (int, int, int, int) ReadInt4() { int[] vs = ReadIntArray(); return (vs[0], vs[1], vs[2], vs[3]); }
    static (int, int, int, int, int) ReadInt5() { int[] vs = ReadIntArray(); return (vs[0], vs[1], vs[2], vs[3], vs[4]); }
    static (long, long) ReadLong2() { long[] vs = ReadLongArray(); return (vs[0], vs[1]); }
    static (long, long, long) ReadLong3() { long[] vs = ReadLongArray(); return (vs[0], vs[1], vs[2]); }

    static void Main()
    {
        SourceExpander.Expander.Expand();

        (int H, int W) = ReadInt2();
        (int A, int B) = ReadInt2();
        A--;
        B--;
        (int R1, int C1, int R2, int C2) = ReadInt4();
        R1--;
        C1--;
        R2--;
        C2--;
        (int P, int Q) = ReadInt2();
        P--; 
        Q--;

        int[,] dists = new int[H, W];
        for (int r = 0; r < H; r++)
        {
            for (int c = 0; c < W; c++)
                dists[r, c] = int.MaxValue;
        }

        Queue<int> X = new Queue<int>();
        Queue<int> Y = new Queue<int>();

        X.Enqueue(B);
        Y.Enqueue(A);
        dists[A, B] = 0;

        int[] dx = { 0, 0, 1, -1 };
        int[] dy = { 1, -1, 0, 0 };

        while (X.Count > 0)
        {
            int c = X.Dequeue();
            int r = Y.Dequeue();
            int d = dists[r, c];
            for (int i = 0; i < 4; i++)
            {
                int nc = c + dx[i];
                int nr = r + dy[i];
                if(nc < 0 || nc >= W || nr < 0 || nr >= H)
                    continue;

                if (dists[nr, nc] > d + 1)
                {
                    dists[nr, nc] = d + 1;
                    Y.Enqueue(nr);
                    X.Enqueue(nc);
                }
            }
        }

        int dist_min = int.MaxValue;
        int near_r = 0;
        int near_c = 0;
        for (int r = R1; r <= R2; r++)
        {
            for (int c = C1; c <= C2; c++)
            {
                if (dist_min > dists[r, c])
                {
                    dist_min = dists[r, c];
                    near_r = r;
                    near_c = c;
                }
            }
        }
        //Console.WriteLine($"{near_r}, {near_c}");
        int ans = dist_min + Math.Abs(P - near_r) + Math.Abs(Q - near_c) + Math.Abs(P - A) + Math.Abs(Q - B);
        Console.WriteLine(ans);

        //Console.WriteLine(dist_min); // 5
        //Console.WriteLine(Math.Abs(P - near_r) + Math.Abs(Q - near_c));
        //Console.WriteLine(Math.Abs(P - A) + Math.Abs(Q - B));
    }
}
#region Expanded by https://github.com/kzrnm/SourceExpander
namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}}
#endregion Expanded by https://github.com/kzrnm/SourceExpander
0