結果

問題 No.402 最も海から遠い場所
ユーザー mbanmban
提出日時 2016-09-17 12:48:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,785 ms / 3,000 ms
コード長 2,094 bytes
コンパイル時間 2,967 ms
コンパイル使用メモリ 115,332 KB
実行使用メモリ 199,472 KB
最終ジャッジ日時 2024-04-28 15:19:18
合計ジャッジ時間 9,126 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,264 KB
testcase_01 AC 30 ms
25,260 KB
testcase_02 AC 31 ms
25,388 KB
testcase_03 AC 30 ms
25,128 KB
testcase_04 AC 31 ms
27,020 KB
testcase_05 AC 29 ms
25,132 KB
testcase_06 AC 30 ms
25,088 KB
testcase_07 AC 30 ms
25,100 KB
testcase_08 AC 30 ms
25,268 KB
testcase_09 AC 30 ms
25,136 KB
testcase_10 AC 30 ms
25,144 KB
testcase_11 AC 30 ms
27,164 KB
testcase_12 AC 29 ms
25,220 KB
testcase_13 AC 36 ms
23,728 KB
testcase_14 AC 32 ms
25,580 KB
testcase_15 AC 67 ms
27,312 KB
testcase_16 AC 83 ms
29,740 KB
testcase_17 AC 683 ms
94,688 KB
testcase_18 AC 1,785 ms
71,920 KB
testcase_19 AC 1,271 ms
199,472 KB
testcase_20 AC 1,258 ms
64,796 KB
testcase_21 AC 1,233 ms
164,024 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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; }
}


0