結果

問題 No.424 立体迷路
ユーザー 14番14番
提出日時 2016-11-08 04:06:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 3,736 bytes
コンパイル時間 2,388 ms
コンパイル使用メモリ 107,540 KB
実行使用メモリ 24,144 KB
最終ジャッジ日時 2023-09-18 16:59:10
合計ジャッジ時間 5,136 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
23,964 KB
testcase_01 AC 63 ms
22,028 KB
testcase_02 AC 62 ms
21,864 KB
testcase_03 AC 63 ms
22,048 KB
testcase_04 AC 63 ms
24,012 KB
testcase_05 AC 62 ms
21,956 KB
testcase_06 AC 63 ms
24,144 KB
testcase_07 AC 62 ms
22,060 KB
testcase_08 AC 62 ms
24,100 KB
testcase_09 AC 62 ms
21,980 KB
testcase_10 AC 63 ms
22,052 KB
testcase_11 AC 63 ms
20,112 KB
testcase_12 AC 63 ms
22,112 KB
testcase_13 AC 64 ms
22,060 KB
testcase_14 AC 63 ms
21,964 KB
testcase_15 AC 64 ms
21,952 KB
testcase_16 AC 63 ms
19,984 KB
testcase_17 AC 64 ms
20,004 KB
testcase_18 AC 64 ms
22,088 KB
testcase_19 AC 64 ms
21,896 KB
testcase_20 AC 63 ms
19,952 KB
testcase_21 AC 64 ms
21,952 KB
testcase_22 AC 64 ms
22,036 KB
testcase_23 AC 63 ms
24,036 KB
testcase_24 AC 65 ms
21,976 KB
testcase_25 AC 65 ms
19,976 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.Text;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();

        int h = inpt[0];
        int w = inpt[1];

        inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        
        int sY = inpt[0] - 1;
        int sX = inpt[1] - 1;

        int gY = inpt[2] - 1;
        int gX = inpt[3] - 1;

        int[,] map = new int[h, w];
        bool[,] flags = new bool[h, w];

        for(int i=0; i<h; i++) {
            string tmp = Reader.ReadLine();
            for(int j=0; j<w; j++) {
                map[i,j] = int.Parse(tmp[j].ToString());
            }        
        }

        flags[sY, sX] = true;
        Queue<int[]> que = new Queue<int[]>();
        que.Enqueue(new int[]{sY, sX});
        while(que.Count > 0) {
            int[] pos = que.Dequeue();
            if(pos[0] == gY && pos[1] == gX) {
                continue;
            }

            List<int[]> next = new List<int[]>();
            for(int i=pos[0]-1; i<=pos[0]+1; i++) {
                for(int j=pos[1]-1; j<=pos[1]+1; j++) {
                    if(i==pos[0] && j==pos[1]) {
                        continue;
                    }
                    if(i!=pos[0] && j!=pos[1]) {
                        continue;
                    }
                    if(i<0||i>=h||j<0||j>=w) {
                        continue;
                    }
                    if(Math.Abs(map[i,j] - map[pos[0], pos[1]]) <= 1) {
                        next.Add(new int[]{i,j});
                    }
                }
            }
            for(int i=pos[0]-2; i<=pos[0]+2; i+=2) {
                for(int j=pos[1]-2; j<=pos[1]+2; j+=2) {
                    if(i==pos[0] && j==pos[1]) {
                        continue;
                    }
                    if(i!=pos[0] && j!=pos[1]) {
                        continue;
                    }
                    if(i<0||i>=h||j<0||j>=w) {
                        continue;
                    }
                    if(map[i,j] == map[pos[0], pos[1]]) {
                        int tani = 0;
                        if(i == pos[0]) {
                            tani = map[i, (pos[1] + j)/2];
                        } else {
                            tani = map[(i+pos[0])/2, j];
                        }
                        if(tani < map[i,j]) {
                            next.Add(new int[]{i,j});
                        }
                    }
                }
            }
            foreach(int[] nextPos in next) {
                if(flags[nextPos[0], nextPos[1]]) {
                    continue;
                }
                flags[nextPos[0], nextPos[1]] = true;
                que.Enqueue(nextPos);
            }
        }

        Console.WriteLine(flags[gY, gX]?"YES":"NO");        
    }


    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"



10 12
4 1 1 12
879572576859
445569966665
033345689389
011246557476
000224557745
000022346548
000000425665
000002223544
000000003223
000000000243



";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0