結果

問題 No.697 池の数はいくつか
ユーザー masayan_kazu
提出日時 2018-06-09 17:24:10
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,722 bytes
コンパイル時間 5,377 ms
コンパイル使用メモリ 112,616 KB
実行使用メモリ 113,620 KB
最終ジャッジ日時 2024-11-25 12:29:49
合計ジャッジ時間 16,323 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 2 WA * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Text;
using System.Threading.Tasks;

namespace ichimatu
{
    class Program
    {
        static char[,] map = new char[3000, 3000];
        static int gyouMax;
        static int retuMax;

        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var d = input.Split(' ');
            gyouMax = Int32.Parse(d[0]);
            retuMax = Int32.Parse(d[1]);

            var input2list = new List<string>();
            for (int i = 0; i < gyouMax; i++)
            {
                input2list.Add(Console.ReadLine());
            }

            for (int i = 0; i < gyouMax; i++)
            {
                var dd = input2list[i].Split(' ');
                for (int j = 0; j < retuMax; j++)
                {
                    map[i, j] = char.Parse(dd[j]);
                }
            }

            var total = 0;
            for (int i = 0; i < gyouMax; i++)
            {
                for (int j = 0; j < retuMax; j++)
                {
                    // 「1」を見つける
                    if (map[i, j] == 1)
                    {
                        // 周辺探索
                        exec周辺探索(i, j);
                        total += 1;
                    }
                }
            }

            Console.WriteLine(total);

        }

        private static void exec周辺探索(int gyou, int retu)
        {
            //var tansaku_gyouList = new List<int>();
            //var tansaku_retuList = new List<int>();
            // 見つけた場所を探索済みにする
            map[gyou, retu] = (char)10;
            // 探索対象をキューに入れる
            // 右をチェックする
            if (retu + 1 < retuMax)
            {
                if (map[gyou, retu + 1] == 1)
                {
                    exec周辺探索(gyou, retu + 1);
                }
            }

            // 上をチェックする
            if (0 <= gyou - 1)
            {
                if (map[gyou - 1, retu] == 1)
                {
                    exec周辺探索(gyou - 1, retu);
                }
            }

            // 下をチェックする
            if (gyou + 1 < gyouMax)
            {
                if (map[gyou + 1, retu] == 1)
                {
                    exec周辺探索(gyou + 1, retu);
                }
            }

            // 左をチェックする
            if (0 <= retu - 1)
            {
                if (map[gyou, retu - 1] == 1)
                {
                    exec周辺探索(gyou, retu - 1);
                }
            }

        }

    }
}
0