結果

問題 No.424 立体迷路
ユーザー jousenjousen
提出日時 2016-09-23 00:40:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 3,874 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 109,148 KB
実行使用メモリ 24,044 KB
最終ジャッジ日時 2023-09-18 16:52:32
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,804 KB
testcase_01 AC 64 ms
21,936 KB
testcase_02 AC 64 ms
21,968 KB
testcase_03 AC 64 ms
21,984 KB
testcase_04 AC 64 ms
19,896 KB
testcase_05 AC 63 ms
23,972 KB
testcase_06 AC 63 ms
22,012 KB
testcase_07 AC 63 ms
21,964 KB
testcase_08 AC 63 ms
21,968 KB
testcase_09 AC 63 ms
24,044 KB
testcase_10 AC 64 ms
21,844 KB
testcase_11 AC 62 ms
21,992 KB
testcase_12 AC 63 ms
23,944 KB
testcase_13 AC 63 ms
21,928 KB
testcase_14 AC 63 ms
21,832 KB
testcase_15 AC 64 ms
23,964 KB
testcase_16 AC 63 ms
21,968 KB
testcase_17 AC 64 ms
21,768 KB
testcase_18 AC 64 ms
23,776 KB
testcase_19 AC 64 ms
21,848 KB
testcase_20 AC 64 ms
23,820 KB
testcase_21 AC 64 ms
23,884 KB
testcase_22 AC 64 ms
22,024 KB
testcase_23 AC 63 ms
23,876 KB
testcase_24 AC 65 ms
23,784 KB
testcase_25 AC 65 ms
21,896 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.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{
			
              var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var position = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var map = new int[input[0], input[1]];

            for(int i =0; i<input[0]; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < s.Length; j++)
                {
                    map[i, j] = s[j];
                }

            }

            var start = new Tuple<int, int>(position[0]-1, position[1]-1);
            var goal = new Tuple<int, int>(position[2]-1, position[3]-1);




            var memo = new bool[input[0], input[1]];

            var dx = new int[] { 0,1,0,-1, 0,2,0,-2};
            var dy = new int[] { 1, 0, -1,0 , 2, 0,-2,0};

            var posi = new Tuple<int, int>(start.Item1, start.Item2);
            memo[posi.Item1, posi.Item2] = true;

            var queue = new Queue<Tuple<int,int>>();

            queue.Enqueue(new Tuple<int,int>(posi.Item1, posi.Item2));
            while(queue.Count()>0)
            {

                Tuple<int, int> current = queue.Dequeue();                

                for (int j = 0; j < 8; j++)
                {
                    int x = current.Item1 + dx[j];
                    int y = current.Item2 + dy[j];

                    if (j / 4 == 0)
                    {
                        if (x >= 0 && x < input[0] && y >= 0 && y < input[1] && !memo[x, y])
                        {
                            if (map[x, y] - 1 == map[current.Item1, current.Item2]
                                || map[x, y] + 1 == map[current.Item1, current.Item2]
                                || map[x, y] == map[current.Item1, current.Item2] )
                            {
                                memo[x, y] = true;
                                queue.Enqueue(new Tuple<int, int>(x,y));
                            }
                        }
                    }
                    else
                    {
                        if (x >= 0 && x < input[0] && y >= 0 && y < input[1] && !memo[x, y])
                        {
                            if (map[x, y] == map[current.Item1, current.Item2])
                            {
                                if (j == 4 && map[x, y - 1] < map[x, y])
                                {
                                    memo[x, y] = true;
                                    queue.Enqueue(new Tuple<int, int>(x, y));
                                }
                                else if (j == 5 && map[x - 1, y] < map[x, y])
                                {
                                    memo[x, y] = true;
                                    queue.Enqueue(new Tuple<int, int>(x, y));
                                }
                                else if (j == 6 && map[x, y + 1] < map[x, y])
                                {
                                    memo[x, y] = true;
                                    queue.Enqueue(new Tuple<int, int>(x, y));
                                }
                                else if (j == 7 && map[x + 1, y] < map[x, y])
                                {
                                    memo[x, y] = true;
                                    queue.Enqueue(new Tuple<int, int>(x, y));
                                }


                            }
                        }
                    }
                }
                           
            }

            if (memo[goal.Item1, goal.Item2]) Console.WriteLine("YES");
            else Console.WriteLine("NO");
            
		}		
		 
	}
}
0