結果

問題 No.424 立体迷路
ユーザー claw88claw88
提出日時 2016-09-22 23:14:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 2,673 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 108,416 KB
実行使用メモリ 26,996 KB
最終ジャッジ日時 2023-09-18 16:50:47
合計ジャッジ時間 5,442 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
24,732 KB
testcase_01 AC 66 ms
22,880 KB
testcase_02 AC 65 ms
22,804 KB
testcase_03 AC 65 ms
20,660 KB
testcase_04 AC 69 ms
24,652 KB
testcase_05 AC 65 ms
22,668 KB
testcase_06 AC 66 ms
24,708 KB
testcase_07 AC 66 ms
22,752 KB
testcase_08 AC 65 ms
22,824 KB
testcase_09 AC 66 ms
22,704 KB
testcase_10 AC 67 ms
20,672 KB
testcase_11 AC 65 ms
22,696 KB
testcase_12 AC 66 ms
24,768 KB
testcase_13 AC 67 ms
22,836 KB
testcase_14 AC 66 ms
22,724 KB
testcase_15 AC 68 ms
22,888 KB
testcase_16 AC 66 ms
22,672 KB
testcase_17 AC 74 ms
24,840 KB
testcase_18 AC 74 ms
24,716 KB
testcase_19 AC 75 ms
24,948 KB
testcase_20 AC 74 ms
24,856 KB
testcase_21 AC 66 ms
22,708 KB
testcase_22 AC 66 ms
22,708 KB
testcase_23 AC 66 ms
22,768 KB
testcase_24 AC 232 ms
26,840 KB
testcase_25 AC 225 ms
26,996 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//key = x, value = y

namespace yuki_424
{
    class Program
    {
        static int h, w;
        static int sx, sy, gx, gy;
        static int[] dx = { -1, 1, 0, 0, -2, 2, 0, 0 };
        static int[] dy = { 0, 0, -1, 1, 0, 0, -2, 2 };
        static void Main(string[] args)
        {
            var t = scan;
            h = t[0]; w = t[1];
            t = scan;
            sx = t[0]-1;sy = t[1]-1;gx = t[2]-1;gy = t[3]-1;

            var M = new Dictionary<Pair, int>();
            var N = new HashSet<Pair>();
            for (int i = 0; i < h; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < w; j++)
                {
                    M[new Pair(i, j)] = int.Parse(s[j].ToString());
                }
            }
          

            
            var Q = new Queue<Pair>();
            Q.Enqueue(new Pair(sx, sy));
            N.Add(new Pair(sx, sy));

            bool flag = false;
            while (Q.Any())
            {
                var u = Q.Dequeue();
                //Console.WriteLine(u.Key+" "+u.Value);
                if(u.Key == gx && u.Value == gy)
                {
                    flag = true;
                    break;
                }
                for (int i = 0; i < 4; i++)
                {
                    var tx = u.Key + dx[i];
                    var ty = u.Value + dy[i];
                    if (tx < 0 || ty < 0 || tx >= h || ty >= w) continue;
                    var p = new Pair(tx, ty);
                    if (Math.Abs(M[p] - M[u]) <= 1 && !N.Contains(p))
                    {
                        Q.Enqueue(p);
                        N.Add(p);
                    }
                }
                for (int i = 4; i < 8; i++)
                {
                    var tx = u.Key + dx[i];
                    var ty = u.Value + dy[i];
                    if (tx < 0 || ty < 0 || tx >= h || ty >= w) continue;
                    var p = new Pair(tx, ty);
                    var s = new Pair((tx + u.Key) / 2, (ty + u.Value) / 2);
                    if (M[p] == M[u] && !N.Contains(p) && M[s] < M[u])
                    {
                        Q.Enqueue(p);
                        N.Add(p);
                    }
                }

            }
            if (flag) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}
0