結果
問題 |
No.424 立体迷路
|
ユーザー |
![]() |
提出日時 | 2016-09-25 18:12:40 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 2,318 bytes |
コンパイル時間 | 854 ms |
コンパイル使用メモリ | 108,544 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-07-05 07:10:08 |
合計ジャッジ時間 | 2,038 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; 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()); } } } }