結果

問題 No.697 池の数はいくつか
ユーザー AreTrashAreTrash
提出日時 2018-06-09 18:39:15
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 1,799 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 115,392 KB
実行使用メモリ 825,096 KB
最終ジャッジ日時 2024-05-04 05:22:14
合計ジャッジ時間 11,438 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
24,112 KB
testcase_01 AC 21 ms
24,072 KB
testcase_02 AC 21 ms
24,104 KB
testcase_03 AC 21 ms
24,068 KB
testcase_04 AC 22 ms
25,896 KB
testcase_05 AC 23 ms
26,024 KB
testcase_06 AC 23 ms
24,108 KB
testcase_07 AC 23 ms
26,108 KB
testcase_08 AC 22 ms
25,888 KB
testcase_09 AC 21 ms
24,072 KB
testcase_10 AC 22 ms
24,072 KB
testcase_11 AC 21 ms
22,068 KB
testcase_12 AC 22 ms
26,148 KB
testcase_13 AC 22 ms
24,076 KB
testcase_14 AC 22 ms
23,948 KB
testcase_15 AC 22 ms
24,196 KB
testcase_16 AC 23 ms
23,940 KB
testcase_17 AC 22 ms
21,812 KB
testcase_18 AC 21 ms
24,068 KB
testcase_19 AC 23 ms
24,076 KB
testcase_20 AC 22 ms
23,984 KB
testcase_21 AC 22 ms
24,104 KB
testcase_22 AC 21 ms
24,068 KB
testcase_23 AC 22 ms
23,988 KB
testcase_24 AC 231 ms
45,292 KB
testcase_25 AC 234 ms
45,684 KB
testcase_26 AC 232 ms
47,488 KB
testcase_27 AC 235 ms
47,356 KB
testcase_28 AC 228 ms
45,440 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace No697
{
    public class Program
    {
        void Solve()
        {
            //---------------------------------
            var input = Console.ReadLine().Split(' ');

            var H = int.Parse(input[0]);
            var W = int.Parse(input[1]);
            var A = new bool[H, W];

            for (var i = 0; i < H; i++)
            {
                input = Console.ReadLine().Split();
                for (var j = 0; j < W; j++) A[i, j] = input[j] == "1";
            }

            int[] dx = { 0, 1, 0, -1 };
            int[] dy = { 1, 0, -1, 0 };
            int dl = 4;
            bool IsInside(int x, int y) => 0 <= x && x < W && 0 <= y && y < H;

            void Bfs(int x, int y)
            {
                var que = new Queue<int>();
                que.Enqueue(x);
                que.Enqueue(y);

                while (que.Count > 0)
                {
                    var cx = que.Dequeue();
                    var cy = que.Dequeue();
                    A[cy, cx] = false;

                    for (var i = 0; i < dl; i++)
                    {
                        var nx = cx + dx[i];
                        var ny = cy + dy[i];
                        if (IsInside(nx, ny) && A[ny, nx]) Bfs(nx, ny);
                    }
                }
            }

            var ans = 0;
            for (var i = 0; i < H; i++)
            for (var j = 0; j < W; j++)
            {
                if (A[i, j])
                {
                    ans++;
                    Bfs(j, i);
                }
            }

            Console.WriteLine(ans);
            //---------------------------------
        }

        static void Main()
        {
            new Program().Solve();
        }
    }
}
0