結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-06-09 15:02:15 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3,243 ms / 6,000 ms | 
| コード長 | 1,933 bytes | 
| コンパイル時間 | 3,664 ms | 
| コンパイル使用メモリ | 104,064 KB | 
| 実行使用メモリ | 76,176 KB | 
| 最終ジャッジ日時 | 2024-11-08 07:32:42 | 
| 合計ジャッジ時間 | 26,971 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
    }
}