結果

問題 No.697 池の数はいくつか
ユーザー AreTrashAreTrash
提出日時 2018-06-09 18:20:02
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 2,057 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 115,436 KB
実行使用メモリ 659,016 KB
最終ジャッジ日時 2024-05-04 05:20:50
合計ジャッジ時間 12,320 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,772 KB
testcase_01 AC 26 ms
21,940 KB
testcase_02 AC 27 ms
28,192 KB
testcase_03 AC 27 ms
26,156 KB
testcase_04 AC 27 ms
24,188 KB
testcase_05 AC 27 ms
26,028 KB
testcase_06 AC 28 ms
25,840 KB
testcase_07 AC 26 ms
23,804 KB
testcase_08 AC 26 ms
23,956 KB
testcase_09 AC 27 ms
26,024 KB
testcase_10 AC 27 ms
23,936 KB
testcase_11 AC 28 ms
25,972 KB
testcase_12 AC 29 ms
26,008 KB
testcase_13 AC 29 ms
24,316 KB
testcase_14 AC 27 ms
22,064 KB
testcase_15 AC 28 ms
25,976 KB
testcase_16 AC 27 ms
21,816 KB
testcase_17 AC 28 ms
22,200 KB
testcase_18 AC 28 ms
23,976 KB
testcase_19 AC 27 ms
26,272 KB
testcase_20 AC 28 ms
24,108 KB
testcase_21 AC 27 ms
23,932 KB
testcase_22 AC 29 ms
25,904 KB
testcase_23 AC 27 ms
23,844 KB
testcase_24 AC 278 ms
47,760 KB
testcase_25 AC 276 ms
45,212 KB
testcase_26 AC 278 ms
47,256 KB
testcase_27 AC 274 ms
45,332 KB
testcase_28 AC 275 ms
47,380 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;
using System.IO;

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

        int H;
        int W;
        bool[,] A;

        void Solve(StreamReader sr, StreamWriter sw)
        {
            //---------------------------------
            var input = sr.ReadLine().Split(' ');

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

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

            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);
                }
            }

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

        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);
                }
            }
        }

        static void Main()
        {
            var ss = new StreamReader(Console.OpenStandardInput());
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }
}
0