結果

問題 No.424 立体迷路
ユーザー mbanmban
提出日時 2016-09-25 18:09:23
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,265 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 108,032 KB
実行使用メモリ 37,120 KB
最終ジャッジ日時 2024-04-29 09:56:34
合計ジャッジ時間 5,008 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
37,120 KB
testcase_01 AC 30 ms
19,072 KB
testcase_02 AC 29 ms
19,072 KB
testcase_03 AC 30 ms
19,328 KB
testcase_04 AC 28 ms
19,072 KB
testcase_05 AC 29 ms
19,328 KB
testcase_06 AC 30 ms
19,200 KB
testcase_07 AC 29 ms
19,200 KB
testcase_08 AC 29 ms
19,328 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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