結果

問題 No.424 立体迷路
ユーザー jousenjousen
提出日時 2016-09-23 00:40:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 3,874 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 108,544 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-07-05 07:07:29
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
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");
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0