結果

問題 No.697 池の数はいくつか
ユーザー バカらっくバカらっく
提出日時 2018-06-09 20:07:04
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,871 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 108,336 KB
実行使用メモリ 77,016 KB
最終ジャッジ日時 2023-08-16 22:11:16
合計ジャッジ時間 26,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,776 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 60 ms
21,836 KB
testcase_09 AC 61 ms
23,920 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 60 ms
23,968 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 60 ms
21,924 KB
testcase_16 AC 61 ms
23,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 61 ms
23,812 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int rowCount = inpt[0];
        int colCount = inpt[1];

        bool[,] map = new bool[rowCount, colCount];
        for (int i = 0; i < rowCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            for (int j = 0; j < colCount; j++) {
                if(inpt[j] == 1) {
                    map[i, j] = true;
                }
            }
        }

        int[,] group = new int[rowCount, colCount];

        int ans = 0;
        for (int i = 0; i < rowCount; i++) {
            for (int j = 0; j < colCount; j++) {
                if(!map[i,j]) {
                    continue;
                }
                if(group[i,j] != 0) {
                    continue;
                }

                ans++;
                group[i, j] = ans;
                Queue<int[]> q = new Queue<int[]>();
                q.Enqueue(new int[]{i,j});
                while(q.Count > 0) {
                    int[] pos = q.Dequeue();
                    for (int k = Math.Max(i - 1, 0); k <= Math.Min(i + 1, rowCount - 1); k++) {
                        for (int l = Math.Max(j - 1, 0); l <= Math.Min(j + 1, colCount - 1); l++) {
                            if(i==k&&j==l) {
                                continue;
                            }
                            if(i!=k && j!=l) {
                                continue;
                            }
                            if(!map[k,l]) {
                                continue;
                            }
                            if(group[k,l] != 0) {
                                continue;
                            }
                            group[k, l] = group[i, j];
                            q.Enqueue(new int[] { k, l });
                        }
                    }
                }
            }
        }
        Console.WriteLine(ans);
    
    }

    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



4 3
1 0 1
0 1 0
1 0 1
0 1 0




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0