結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2016-09-17 12:48:27 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,800 ms / 3,000 ms |
コード長 | 2,094 bytes |
コンパイル時間 | 5,004 ms |
コンパイル使用メモリ | 113,524 KB |
実行使用メモリ | 193,312 KB |
最終ジャッジ日時 | 2024-11-17 08:15:31 |
合計ジャッジ時間 | 14,204 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static int H, W; static int[,] S; static int[] tate = { -1, 0, 1, -1, 1, -1, 0, 1 }, yoko = { -1, -1, -1, 0, 0, 1, 1, 1 }; static void Main() { int[] q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); H = q[0]; W = q[1]; Queue<XY> Q = new Queue<XY>(); S = new int[H + 2, W + 2]; for (int i = 0; i < W + 2; i++) { S[0, i] = 0; Q.Enqueue(new XY(0, i)); S[H + 1, i] = 0; Q.Enqueue(new XY(H + 1, i)); } for (int i = 0; i < H; i++) { string qw = Console.ReadLine(); for (int j = 0; j < W + 2; j++) { if (j == 0 || j == W + 1 || qw[j - 1] == '.') { S[i + 1, j] = 0; Q.Enqueue(new XY(i + 1, j)); } else { S[i + 1, j] = -1; } } } while (Q.Count > 0) { XY xy = Q.Dequeue(); for(int i = 0; i < 8; i++) { if (tate[i] + xy.Y >= 0 && tate[i] + xy.Y <= H + 1 && yoko[i] + xy.X >= 0 && yoko[i]+xy.X <= W + 1) { if (S[tate[i] + xy.Y, yoko[i] + xy.X] == -1) { S[tate[i] + xy.Y, yoko[i] + xy.X] = S[xy.Y, xy.X] + 1; Q.Enqueue(new XY(tate[i] + xy.Y, yoko[i] + xy.X)); } } } } int max = int.MinValue; for(int i= 1;i<= H; i++) { for(int j = 1; j <= W; j++) { max = Math.Max(max, S[i, j]); } } Console.WriteLine(max); } } public struct XY { public XY(int y,int x) { this.X = x; this.Y = y; } public int Y { get; set; } public int X { get; set; } }