結果
問題 | No.402 最も海から遠い場所 |
ユーザー | eitaho |
提出日時 | 2016-07-26 21:58:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 2,154 ms / 3,000 ms |
コード長 | 3,891 bytes |
コンパイル時間 | 4,199 ms |
コンパイル使用メモリ | 115,880 KB |
実行使用メモリ | 282,476 KB |
最終ジャッジ日時 | 2024-11-06 17:09:26 |
合計ジャッジ時間 | 13,275 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
24,012 KB |
testcase_01 | AC | 27 ms
24,128 KB |
testcase_02 | AC | 29 ms
24,240 KB |
testcase_03 | AC | 27 ms
24,152 KB |
testcase_04 | AC | 27 ms
23,984 KB |
testcase_05 | AC | 28 ms
26,184 KB |
testcase_06 | AC | 27 ms
24,128 KB |
testcase_07 | AC | 28 ms
21,812 KB |
testcase_08 | AC | 29 ms
24,124 KB |
testcase_09 | AC | 28 ms
21,936 KB |
testcase_10 | AC | 27 ms
28,224 KB |
testcase_11 | AC | 29 ms
24,028 KB |
testcase_12 | AC | 28 ms
24,256 KB |
testcase_13 | AC | 38 ms
25,916 KB |
testcase_14 | AC | 31 ms
23,852 KB |
testcase_15 | AC | 80 ms
26,048 KB |
testcase_16 | AC | 103 ms
30,776 KB |
testcase_17 | AC | 995 ms
120,872 KB |
testcase_18 | AC | 2,154 ms
112,788 KB |
testcase_19 | AC | 1,979 ms
282,476 KB |
testcase_20 | AC | 1,972 ms
112,776 KB |
testcase_21 | AC | 1,921 ms
210,028 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int H = Reader.Int() + 2, W = Reader.Int() + 2; var grid = Reader.StringArray(H - 2); grid = Surround(grid, '.'); var que = new Queue<int>(); var minDist = new int[H, W]; Fill(minDist, H + W + 10); Func<int, int, bool> IsInside = (r, c) => r >= 0 && r < H && c >= 0 && c < W; for (int r = 0; r < H; r++) for (int c = 0; c < W; c++) if (grid[r][c] == '.') { que.Enqueue(r); que.Enqueue(c); minDist[r, c] = 0; } while (que.Count > 0) { int r = que.Dequeue(), c = que.Dequeue(); for (int dr = -1; dr <= 1; dr++) for (int dc = -1; dc <= 1; dc++) { int nr = r + dr, nc = c + dc; if (IsInside(nr, nc) && CheckMin(ref minDist[nr, nc], minDist[r, c] + 1)) { que.Enqueue(nr); que.Enqueue(nc); } } } int ans = 0; for (int r = 0; r < H; r++) for (int c = 0; c < W; c++) CheckMax(ref ans, minDist[r, c]); Console.WriteLine(ans); } bool CheckMin(ref int a, int b) { if (b < a) { a = b; return true; } return false; } bool CheckMax(ref int a, int b) { if (b > a) { a = b; return true; } return false; } string[] Surround(string[] grid, char c) { int H = grid.Length + 2, W = grid[0].Length + 2; var res = new string[H]; for (int i = 0; i < H; i++) if (i == 0 || i == H - 1) res[i] = new string(c, W); else res[i] = c + grid[i - 1] + c; return res; } void Fill<T>(T[,] A, T val) { for (int a = 0; a < A.GetLength(0); a++) for (int b = 0; b < A.GetLength(1); b++) A[a, b] = val; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } static string[] Split(string s) { return s.Split(separator, op); } static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }