結果

問題 No.697 池の数はいくつか
ユーザー chika0707chika0707
提出日時 2019-04-17 23:23:53
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,515 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 65,904 KB
実行使用メモリ 157,412 KB
最終ジャッジ日時 2023-08-16 23:02:41
合計ジャッジ時間 20,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,536 KB
testcase_01 AC 60 ms
21,504 KB
testcase_02 AC 61 ms
23,484 KB
testcase_03 AC 62 ms
23,484 KB
testcase_04 AC 61 ms
21,508 KB
testcase_05 AC 61 ms
23,512 KB
testcase_06 AC 61 ms
21,528 KB
testcase_07 AC 61 ms
21,500 KB
testcase_08 AC 59 ms
21,468 KB
testcase_09 AC 62 ms
23,480 KB
testcase_10 AC 61 ms
23,512 KB
testcase_11 AC 60 ms
21,484 KB
testcase_12 AC 59 ms
21,440 KB
testcase_13 AC 60 ms
21,424 KB
testcase_14 AC 61 ms
23,576 KB
testcase_15 AC 61 ms
21,480 KB
testcase_16 AC 60 ms
21,440 KB
testcase_17 AC 60 ms
23,596 KB
testcase_18 AC 61 ms
23,568 KB
testcase_19 AC 61 ms
21,496 KB
testcase_20 AC 61 ms
21,460 KB
testcase_21 AC 61 ms
21,584 KB
testcase_22 AC 60 ms
21,452 KB
testcase_23 AC 60 ms
21,628 KB
testcase_24 AC 2,535 ms
48,224 KB
testcase_25 AC 5,604 ms
157,412 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; public Pair(int xx, int yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        int H = NextInt();
        int W = NextInt();
        int[,] map = new int[H, W];
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++) map[i, j] = NextInt();
        //池の水全部抜く
        Queue<Pair> Q = new Queue<Pair>();
        int ans = 0;
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
            {
                if (map[i, j] != 1) continue;
                Pair P = new Pair(j, i);
                Q.Enqueue(P);
                while (Q.Count() != 0)
                {
                    Pair pos = Q.Dequeue();
                    map[pos.y, pos.x] = 0;
                    for (int d = 0; d < 4; d++)
                    {
                        int xx = pos.x + dx[d];
                        int yy = pos.y + dy[d];
                        if (xx < 0 || W <= xx || yy < 0 || H <= yy) continue;
                        if (map[yy, xx] == 1) Q.Enqueue(new Pair(xx, yy));
                    }
                }
                ans++;
            }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}
0