結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-22 23:14:28 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 159 ms / 2,000 ms |
| コード長 | 2,673 bytes |
| コンパイル時間 | 942 ms |
| コンパイル使用メモリ | 113,588 KB |
| 実行使用メモリ | 24,548 KB |
| 最終ジャッジ日時 | 2024-07-05 07:06:20 |
| 合計ジャッジ時間 | 2,455 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//key = x, value = y
namespace yuki_424
{
class Program
{
static int h, w;
static int sx, sy, gx, gy;
static int[] dx = { -1, 1, 0, 0, -2, 2, 0, 0 };
static int[] dy = { 0, 0, -1, 1, 0, 0, -2, 2 };
static void Main(string[] args)
{
var t = scan;
h = t[0]; w = t[1];
t = scan;
sx = t[0]-1;sy = t[1]-1;gx = t[2]-1;gy = t[3]-1;
var M = new Dictionary<Pair, int>();
var N = new HashSet<Pair>();
for (int i = 0; i < h; i++)
{
string s = Console.ReadLine();
for (int j = 0; j < w; j++)
{
M[new Pair(i, j)] = int.Parse(s[j].ToString());
}
}
var Q = new Queue<Pair>();
Q.Enqueue(new Pair(sx, sy));
N.Add(new Pair(sx, sy));
bool flag = false;
while (Q.Any())
{
var u = Q.Dequeue();
//Console.WriteLine(u.Key+" "+u.Value);
if(u.Key == gx && u.Value == gy)
{
flag = true;
break;
}
for (int i = 0; i < 4; i++)
{
var tx = u.Key + dx[i];
var ty = u.Value + dy[i];
if (tx < 0 || ty < 0 || tx >= h || ty >= w) continue;
var p = new Pair(tx, ty);
if (Math.Abs(M[p] - M[u]) <= 1 && !N.Contains(p))
{
Q.Enqueue(p);
N.Add(p);
}
}
for (int i = 4; i < 8; i++)
{
var tx = u.Key + dx[i];
var ty = u.Value + dy[i];
if (tx < 0 || ty < 0 || tx >= h || ty >= w) continue;
var p = new Pair(tx, ty);
var s = new Pair((tx + u.Key) / 2, (ty + u.Value) / 2);
if (M[p] == M[u] && !N.Contains(p) && M[s] < M[u])
{
Q.Enqueue(p);
N.Add(p);
}
}
}
if (flag) Console.WriteLine("YES");
else Console.WriteLine("NO");
}
static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
}
}