結果

問題 No.402 最も海から遠い場所
ユーザー 14番14番
提出日時 2016-09-01 08:02:08
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 4,412 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 112,136 KB
実行使用メモリ 825,804 KB
最終ジャッジ日時 2024-04-26 22:25:31
合計ジャッジ時間 8,728 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
19,200 KB
testcase_01 AC 28 ms
19,072 KB
testcase_02 AC 31 ms
20,396 KB
testcase_03 AC 28 ms
18,944 KB
testcase_04 AC 28 ms
19,200 KB
testcase_05 AC 28 ms
18,944 KB
testcase_06 AC 27 ms
19,072 KB
testcase_07 AC 28 ms
18,944 KB
testcase_08 AC 28 ms
19,072 KB
testcase_09 AC 28 ms
19,200 KB
testcase_10 AC 27 ms
19,200 KB
testcase_11 AC 28 ms
19,684 KB
testcase_12 AC 29 ms
19,072 KB
testcase_13 AC 85 ms
39,424 KB
testcase_14 AC 53 ms
27,136 KB
testcase_15 AC 367 ms
94,400 KB
testcase_16 AC 673 ms
119,792 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];

        char[,] map = new char[h, w];

        Queue<int[]> taskQue = new Queue<int[]>();

        for (int i = 0; i < inpt[0]; i++)
        {
            string row = Reader.ReadLine();
            for (int j = 0; j < inpt[1]; j++)
            {
                map[i, j] = row[j];
                if (row[j] == '.')
                {
                    for (int k = Math.Max(0, i - 1); k <= Math.Min(h - 1, i + 1); k++)
                    {
                        for (int l = Math.Max(0, j - 1); l <= Math.Min(w - 1, j + 1); l++)
                        {
                            if(i==k && l==j) {
                                continue;
                            }
                            taskQue.Enqueue(new int[] { k, l });
                        }
                    }
                }
                else if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                {
                    taskQue.Enqueue(new int[] { i, j });
                }
            }
        }


        int[,] step = new int[h, w];
        int maxNewval = 0;
        while (taskQue.Count > 0)
        {
            int[] pos = taskQue.Dequeue();

            if(map[pos[0], pos[1]] == '.') {
                continue;
            }
            int oldVal = step[pos[0], pos[1]];

            int newVal = oldVal;
            if (pos[0] == 0 || pos[0] == h - 1 || pos[1] == 0 || pos[1] == w - 1)
            {
                newVal = 1;
            }
            else
            {
                for (int i = pos[0] - 1; i <= pos[0] + 1; i++)
                {
                    bool mustBreak = false;
                    for (int j = pos[1] - 1; j <= pos[1] + 1; j++)
                    {
                        if (i == pos[0] && j == pos[1])
                        {
                            continue;
                        }
                        if (map[i, j] == '.')
                        {
                            newVal = 1;
                            mustBreak = true;
                            break;
                        }
                        else if (step[i, j] > 0)
                        {
                            if (newVal == 0)
                            {
                                newVal = step[i, j] + 1;
                            }
                            else
                            {
                                newVal = Math.Min(newVal, step[i, j] + 1);
                            }
                        }
                    }
                    if (mustBreak)
                    {
                        break;
                    }
                }
            }
            if (oldVal != newVal)
            {
                step[pos[0], pos[1]] = newVal;
                maxNewval = Math.Max(maxNewval, newVal);
                for (int i = Math.Max(0, pos[0] - 1); i <= Math.Min(h - 1, pos[0] + 1); i++)
                {
                    for (int j = Math.Max(0, pos[1] - 1); j <= Math.Min(w - 1, pos[1] + 1); j++)
                    {
                        if (i == pos[0] && j == pos[1])
                        {
                            continue;
                        }
                        taskQue.Enqueue(new int[] { i, j });
                    }
                }
            }
        }
        Console.WriteLine(maxNewval);
    
    }




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


8 8
.#..#...
.######.
#####...
#####.#.
########
######.#
#####...
...####.




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