結果

問題 No.402 最も海から遠い場所
ユーザー aketijyuuzouaketijyuuzou
提出日時 2024-10-13 08:01:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,264 ms / 3,000 ms
コード長 7,942 bytes
コンパイル時間 1,122 ms
コンパイル使用メモリ 110,336 KB
実行使用メモリ 100,352 KB
最終ジャッジ日時 2024-10-13 08:01:20
合計ジャッジ時間 13,999 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
19,712 KB
testcase_01 AC 32 ms
19,840 KB
testcase_02 AC 33 ms
19,840 KB
testcase_03 AC 32 ms
19,712 KB
testcase_04 AC 34 ms
19,712 KB
testcase_05 AC 32 ms
19,584 KB
testcase_06 AC 31 ms
19,712 KB
testcase_07 AC 32 ms
19,712 KB
testcase_08 AC 33 ms
19,712 KB
testcase_09 AC 32 ms
19,712 KB
testcase_10 AC 32 ms
19,712 KB
testcase_11 AC 34 ms
19,712 KB
testcase_12 AC 32 ms
19,584 KB
testcase_13 AC 43 ms
20,748 KB
testcase_14 AC 37 ms
20,088 KB
testcase_15 AC 86 ms
25,088 KB
testcase_16 AC 110 ms
25,856 KB
testcase_17 AC 1,110 ms
58,752 KB
testcase_18 AC 2,264 ms
100,224 KB
testcase_19 AC 2,074 ms
100,224 KB
testcase_20 AC 2,261 ms
100,352 KB
testcase_21 AC 2,181 ms
100,096 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.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("8 8");
            WillReturn.Add(".#..#...");
            WillReturn.Add(".######.");
            WillReturn.Add("#####...");
            WillReturn.Add("#####.#.");
            WillReturn.Add("########");
            WillReturn.Add("######.#");
            WillReturn.Add("#####...");
            WillReturn.Add("...####.");
            //3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("7 7");
            WillReturn.Add("#######");
            WillReturn.Add("#######");
            WillReturn.Add("#######");
            WillReturn.Add("#######");
            WillReturn.Add("#.#####");
            WillReturn.Add("#..####");
            WillReturn.Add("#######");
            //3
        }
        else if (InputPattern == "Input3") {
            List<string> P = WillReturn;
            P.Add("60 60");
            P.Add("............................................................");
            P.Add("............................................................");
            P.Add("........................................#...............##..");
            P.Add(".......................................####............##...");
            P.Add(".........................................##...........##....");
            P.Add(".........................................###........#.......");
            P.Add(".........................................#####...#..#.......");
            P.Add(".........................................#########....#.....");
            P.Add("........................................###########.........");
            P.Add("........................................#############.......");
            P.Add(".....................................##.##########..........");
            P.Add("......................................#########.............");
            P.Add(".....................................#########..............");
            P.Add("....................................##.#...###..............");
            P.Add("...................................###.......#..............");
            P.Add(".....................................###....................");
            P.Add(".....................................#......................");
            P.Add(".......................................##...................");
            P.Add("......................................#.#...................");
            P.Add(".....................................####...................");
            P.Add(".....................................####...................");
            P.Add(".....................................#####..................");
            P.Add(".....................................######.................");
            P.Add(".....................................######.................");
            P.Add(".....................................######.................");
            P.Add(".....................................#####..................");
            P.Add("....................................#####...................");
            P.Add("....................................#####...................");
            P.Add("....................................######..................");
            P.Add("...................................#####....................");
            P.Add("................................#.######....................");
            P.Add(".................................#######....................");
            P.Add("............................#...########....................");
            P.Add("............................#.##########....................");
            P.Add("...........................############.....................");
            P.Add("...........................############.....................");
            P.Add("..........................#############.....................");
            P.Add(".........................###############....................");
            P.Add("....................###..##############.....................");
            P.Add("...............#####################.##.....................");
            P.Add("..............###################.#..#......................");
            P.Add(".....#......###############.####..#.........................");
            P.Add("..........########......###.................................");
            P.Add("..........####....##.#.#####................................");
            P.Add("......#.##...#.######..###..................................");
            P.Add(".....##.####...######..##...................................");
            P.Add("......######..####.#........................................");
            P.Add("...#...######.###...........................................");
            P.Add("......##.####..#............................................");
            P.Add(".......#.###................................................");
            P.Add("........####................................................");
            P.Add(".......####.................................................");
            P.Add(".......####.................................................");
            P.Add(".......#.##.................................................");
            P.Add("............................................................");
            P.Add("..........#.................................................");
            P.Add("........#.#.................................................");
            P.Add("............................................................");
            P.Add("............................................................");
            P.Add("............................................................");
            //4
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static int UB_X;
    static int UB_Y;

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int H = wkArr[0];
        int W = wkArr[1];

        UB_X = W - 1;
        UB_Y = H - 1;
        char[,] BanArr = new char[UB_X + 1, UB_Y + 1];

        for (int LoopX = 0; LoopX <= UB_X; LoopX++) {
            for (int LoopY = 0; LoopY <= UB_Y; LoopY++) {
                BanArr[LoopX, LoopY] = InputList[LoopY + 1][LoopX];
            }
        }

        int[,] CntArr = new int[UB_X + 1, UB_Y + 1];

        Func<int, int, int> wkFunc = (pX, pY) =>
        {
            if (pX < 0 || UB_X < pX) return 0;
            if (pY < 0 || UB_Y < pY) return 0;

            return CntArr[pX, pY];
        };

        for (int LoopX = 0; LoopX <= UB_X; LoopX++) {
            for (int LoopY = 0; LoopY <= UB_Y; LoopY++) {
                if (BanArr[LoopX, LoopY] == '.')
                    CntArr[LoopX, LoopY] = 0;
                else {
                    int Cnt1 = wkFunc(LoopX - 1, LoopY - 1);
                    int Cnt2 = wkFunc(LoopX, LoopY - 1);
                    int Cnt3 = wkFunc(LoopX - 1, LoopY);

                    int wkMin = Math.Min(Cnt1, Cnt2);
                    wkMin = Math.Min(wkMin, Cnt3);

                    CntArr[LoopX, LoopY] = wkMin + 1;
                }
            }
        }

        int MaxSeihoukeiLength = CntArr.Cast<int>().Max();
        if (MaxSeihoukeiLength % 2 == 0) Console.WriteLine(MaxSeihoukeiLength / 2);
        else Console.WriteLine(MaxSeihoukeiLength / 2 + 1);
    }
}

0