結果

問題 No.697 池の数はいくつか
ユーザー yuki2006yuki2006
提出日時 2018-06-09 15:02:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 3,289 ms / 6,000 ms
コード長 1,933 bytes
コンパイル時間 3,720 ms
コンパイル使用メモリ 109,956 KB
実行使用メモリ 85,808 KB
最終ジャッジ日時 2024-04-25 19:51:27
合計ジャッジ時間 28,268 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,292 KB
testcase_01 AC 25 ms
24,040 KB
testcase_02 AC 25 ms
21,940 KB
testcase_03 AC 25 ms
24,156 KB
testcase_04 AC 25 ms
24,176 KB
testcase_05 AC 26 ms
24,428 KB
testcase_06 AC 25 ms
24,160 KB
testcase_07 AC 26 ms
24,296 KB
testcase_08 AC 25 ms
24,044 KB
testcase_09 AC 26 ms
24,040 KB
testcase_10 AC 26 ms
24,040 KB
testcase_11 AC 26 ms
24,040 KB
testcase_12 AC 25 ms
24,048 KB
testcase_13 AC 26 ms
24,296 KB
testcase_14 AC 25 ms
24,296 KB
testcase_15 AC 26 ms
24,176 KB
testcase_16 AC 25 ms
24,116 KB
testcase_17 AC 26 ms
24,044 KB
testcase_18 AC 25 ms
24,172 KB
testcase_19 AC 26 ms
24,160 KB
testcase_20 AC 25 ms
24,044 KB
testcase_21 AC 27 ms
24,296 KB
testcase_22 AC 26 ms
26,080 KB
testcase_23 AC 25 ms
24,244 KB
testcase_24 AC 348 ms
47,280 KB
testcase_25 AC 349 ms
49,596 KB
testcase_26 AC 347 ms
47,540 KB
testcase_27 AC 347 ms
49,720 KB
testcase_28 AC 350 ms
41,736 KB
testcase_29 AC 3,281 ms
76,052 KB
testcase_30 AC 2,823 ms
83,744 KB
testcase_31 AC 3,289 ms
83,756 KB
testcase_32 AC 2,826 ms
85,808 KB
testcase_33 AC 2,836 ms
79,772 KB
testcase_34 AC 2,832 ms
82,280 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;

class Program
{

    Program()
    {

        int[] A = getValues(Console.ReadLine());

        int H = A[0];
        int W = A[1];

        int[][] field = new int[H][];
        for (int i = 0; i < H; i++)
        {
            field[i] = getValues(Console.ReadLine());
        }

        int rake = 0;

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (field[i][j] == 1)
                {
                    rake++;
                    check(field, i, j);
                }
            }
        }
        Console.WriteLine(rake);
    }

    void check(int[][] field, int sx, int sy)
    {
        Queue<Tuple<int, int>> queue = new Queue<Tuple<int, int>>();
        queue.Enqueue(new Tuple<int, int>(sx, sy));

        field[sx][sy] = 0;
        while (queue.Count > 0)
        {
            var P = queue.Dequeue();

            int x1 = P.Item1;
            int y1 = P.Item2;

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (Math.Abs(i + j) != 1)
                    {
                        continue;
                    }
                    int x = x1 + i;
                    int y = y1 + j;
                    if (0 <= x && x < field.Length && 0 <= y && y < field[0].Length && field[x][y] == 1)
                    {
                        field[x][y] = 0;
                        queue.Enqueue(new Tuple<int, int>(x, y));
                    }
                }
            }
        }
    }


    static int[] getValues(string s)
    {
        string[] A = s.Split();
        int[] B = new int[A.Length];
        for (int i = 0; i < A.Length; i++)
        {
            B[i] = int.Parse(A[i]);
        }
        return B;
    }

    static void Main(string[] args)
    {
        new Program();
    }
}
0