結果

問題 No.424 立体迷路
ユーザー mbanmban
提出日時 2016-09-25 18:12:40
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,318 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 104,180 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2023-09-18 16:55:21
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,884 KB
testcase_01 AC 60 ms
21,932 KB
testcase_02 AC 60 ms
21,908 KB
testcase_03 AC 60 ms
21,988 KB
testcase_04 AC 61 ms
24,000 KB
testcase_05 AC 60 ms
21,900 KB
testcase_06 AC 60 ms
21,928 KB
testcase_07 AC 60 ms
19,928 KB
testcase_08 AC 61 ms
22,064 KB
testcase_09 AC 60 ms
21,904 KB
testcase_10 AC 59 ms
21,984 KB
testcase_11 AC 59 ms
21,932 KB
testcase_12 AC 60 ms
23,868 KB
testcase_13 AC 60 ms
23,880 KB
testcase_14 AC 59 ms
21,912 KB
testcase_15 AC 59 ms
21,944 KB
testcase_16 AC 60 ms
21,944 KB
testcase_17 AC 60 ms
21,976 KB
testcase_18 AC 61 ms
22,036 KB
testcase_19 AC 62 ms
21,876 KB
testcase_20 AC 61 ms
23,900 KB
testcase_21 AC 62 ms
25,984 KB
testcase_22 AC 60 ms
21,968 KB
testcase_23 AC 60 ms
21,840 KB
testcase_24 AC 61 ms
22,000 KB
testcase_25 AC 62 ms
23,908 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;


class Magatro {
    static int h, w;
    static int sx, sy, gx, gy;
    static int[,] b;
    static int[] x = { 0, 1, -1, 0 };
    static int[] y = { 1, 0, 0, -1 };
   static void Main() {
        
        Read();
        bool[,] qq = new bool[h, w];
        Queue<int> qx=new Queue<int>(), qy=new Queue<int>();
        qx.Enqueue(sx);
        qy.Enqueue(sy);
        while (qx.Count > 0) {
            int cx = qx.Dequeue();
            int cy = qy.Dequeue();
            for(int i = 0; i < 4; i++) {
                if (cx + x[i] >= 0 && cx + x[i] < w && cy + y[i] >= 0 && cy + y[i] < h) {
                   if(!qq[y[i] + cy, x[i] + cx]) {
                        if(Math.Abs(b[y[i] + cy, x[i] + cx] - b[cy, cx]) <= 1) {
                            qq[y[i] + cy, x[i] + cx] = true;
                            qx.Enqueue(x[i] + cx);
                            qy.Enqueue(y[i] + cy);
                        }
                    }
                }
                if (cx + 2*x[i] >= 0 && cx + 2*x[i] < w && cy + 2*y[i] >= 0 && cy + 2*y[i] < h) {
                    if (!qq[2*y[i] + cy, 2*x[i] + cx]) {
                        if (b[2*y[i] + cy, 2*x[i] + cx] == b[cy, cx]) {
                            if (b[y[i] + cy, x[i] + cx] < b[cy, cx]) {
                                qq[2 * y[i] + cy, 2 * x[i] + cx] = true;
                                qx.Enqueue(2 * x[i] + cx);
                                qy.Enqueue(2 * y[i] + cy);
                            }
                        }
                    }
                }

            }
        }
        if (qq[gy, gx]) {
            Console.WriteLine("YES");
        }
        else {
            Console.WriteLine("NO");
        }
    }
    static void Read() {
        int[] q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        h = q[0];
        w = q[1];
        q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        sx = q[1]-1;
        sy = q[0]-1;
        gx = q[3]-1;
        gy = q[2]-1;
        b = new int[h, w];
        for(int i = 0; i < h; i++) {
            string s = Console.ReadLine();
            for(int j = 0; j < w; j++) {
                b[i, j] = int.Parse(s[j].ToString());
            }
        }
    }


}
0