結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-11-08 04:06:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 3,736 bytes |
コンパイル時間 | 807 ms |
コンパイル使用メモリ | 109,952 KB |
実行使用メモリ | 19,712 KB |
最終ジャッジ日時 | 2024-07-05 07:12:24 |
合計ジャッジ時間 | 2,366 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.
ソースコード
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 124 1 1 12879572576859445569966665033345689389011246557476000224557745000022346548000000425665000002223544000000003223000000000243";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();}}