結果

問題 No.424 立体迷路
ユーザー bluemeganebluemegane
提出日時 2018-09-16 19:20:14
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,115 bytes
コンパイル時間 3,768 ms
コンパイル使用メモリ 106,188 KB
実行使用メモリ 23,496 KB
最終ジャッジ日時 2023-09-25 09:06:52
合計ジャッジ時間 6,221 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
23,496 KB
testcase_01 AC 60 ms
21,376 KB
testcase_02 AC 61 ms
23,436 KB
testcase_03 AC 60 ms
21,336 KB
testcase_04 AC 61 ms
23,440 KB
testcase_05 AC 61 ms
23,464 KB
testcase_06 AC 62 ms
21,392 KB
testcase_07 AC 61 ms
21,472 KB
testcase_08 AC 60 ms
21,408 KB
testcase_09 AC 60 ms
21,508 KB
testcase_10 AC 60 ms
21,356 KB
testcase_11 WA -
testcase_12 AC 62 ms
21,352 KB
testcase_13 WA -
testcase_14 AC 61 ms
21,436 KB
testcase_15 WA -
testcase_16 AC 61 ms
21,344 KB
testcase_17 AC 62 ms
21,608 KB
testcase_18 AC 61 ms
21,516 KB
testcase_19 AC 62 ms
21,528 KB
testcase_20 AC 62 ms
21,552 KB
testcase_21 AC 60 ms
23,432 KB
testcase_22 WA -
testcase_23 AC 60 ms
21,440 KB
testcase_24 AC 63 ms
21,384 KB
testcase_25 AC 62 ms
21,572 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var sx = int.Parse(line[0]) - 1;
        var sy = int.Parse(line[1]) - 1;
        var gx = int.Parse(line[2]) -1;
        var gy = int.Parse(line[3]) -1;
        var map = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                map[i, j] = int.Parse(s[j].ToString());
        }
        var res = goDfs(map, sx, sy, gx, gy);
        Console.WriteLine(res ? "YES":"NO");
    }
    public static bool goDfs (int[,] map , int sx, int sy, int gx, int gy)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        var dx = new int[] { 0, 1, 0, -1 };
        var dy = new int[] { 1, 0, -1, 0 };
        var used = new bool[h, w];
        var st = new Stack<P>();
        st.Push(new P { x = sx, y = sy });
        used[sx, sy] = true;
        while (st.Count() > 0)
        {
            var a = st.Pop();
            if (a.x == gx && a.y == gy) return true;
            used[a.x, a.y] = true;
            for (int i = 0; i < 4; i++)
            {
                var nx = a.x + dx[i];
                var ny = a.y + dy[i];
                var nx2 = a.x + 2 * dx[i];
                var ny2 = a.y + 2 * dy[i];
                var nxm = (a.x + nx2) / 2;
                var nym = (a.y + ny2) / 2;
                if (nx >= 0 && nx < h && ny >= 0 && ny < w && Math.Abs(map[nx, ny] - map[a.x, a.y] )<= 1 && !used[nx, ny]) st.Push(new P { x = nx, y = ny });
                if (nx2 >= 0 && nx2 < h && ny2 >= 0 && ny2 < w && map[nxm,nym]< map[a.x,a.y] && map[nxm,nym] < map[nx2,ny2] && !used[nx2,ny2] ) st.Push(new P { x = nx2, y = ny2});
            }
        }
        return false;
    }
}
0