結果

問題 No.402 最も海から遠い場所
ユーザー 14番14番
提出日時 2016-07-23 00:00:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,692 bytes
コンパイル時間 3,191 ms
コンパイル使用メモリ 108,288 KB
実行使用メモリ 752,524 KB
最終ジャッジ日時 2024-04-24 06:32:21
合計ジャッジ時間 8,875 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,320 KB
testcase_01 AC 30 ms
18,816 KB
testcase_02 AC 30 ms
19,584 KB
testcase_03 AC 29 ms
19,328 KB
testcase_04 AC 29 ms
19,328 KB
testcase_05 AC 29 ms
19,200 KB
testcase_06 AC 29 ms
19,200 KB
testcase_07 AC 29 ms
19,328 KB
testcase_08 AC 30 ms
18,944 KB
testcase_09 WA -
testcase_10 AC 29 ms
18,944 KB
testcase_11 AC 31 ms
19,328 KB
testcase_12 AC 29 ms
19,456 KB
testcase_13 AC 62 ms
32,768 KB
testcase_14 AC 46 ms
28,032 KB
testcase_15 WA -
testcase_16 AC 505 ms
126,752 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Text;
using System.Linq;



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

        int[,] step = new int[H, W];

        char[,] map = new char[H, W];

        Queue<int[]> q = new Queue<int[]>();
        for(int i=0; i<H; i++) {
            string tmp = Reader.ReadLine();
            for(int j=0; j<tmp.Length; j++) {
                map[i,j] = tmp[j];
                if(tmp[j] == '.') {
                    int[] t = new int[]{i, j, 0};
                    q.Enqueue(t);
                }
                else if(i==0 || i == H-1 || j == 0 || j == W-1) {
                    int[] t = new int[]{i, j, 1};
                    q.Enqueue(t);
                }
            }
        }
        while (q.Count > 0)
        {
            int[] task = q.Dequeue();
            int posY = task[0];
            int posX = task[1];
            int cnt = task[2];

            if((step[posY, posX] == 0 && map[posY, posX] == '#') || (cnt == 0 && map[posY , posX] == '.')) {
                step[posY, posX] = cnt;
                for(int i = Math.Max(0, posY-1); i<= Math.Min(H-1, posY+1); i++) {
                    for(int j=Math.Max(0, posX - 1); j<= Math.Min(W-1, posX+1); j++) {
                        if(i==posY && j == posX) {
                            continue;
                        }
                        if(map[i,j] == '#' ) {
                            int[] newT = new int[]{i,j, cnt+1};
                            q.Enqueue(newT);
                        }
                    }
                }
            }
        }

        int ans = 0;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                ans = Math.Max(ans, step[i,j]);
            }
        }
        Console.WriteLine(ans);



    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

7 7
#######
#######
#######
#######
#.#####
#..####
#######


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0