結果

問題 No.697 池の数はいくつか
ユーザー chika0707chika0707
提出日時 2019-04-17 23:28:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,904 ms / 6,000 ms
コード長 2,544 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 115,484 KB
実行使用メモリ 85,856 KB
最終ジャッジ日時 2024-04-25 20:26:56
合計ジャッジ時間 22,193 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
23,216 KB
testcase_01 AC 25 ms
24,968 KB
testcase_02 AC 24 ms
26,884 KB
testcase_03 AC 24 ms
26,892 KB
testcase_04 AC 24 ms
25,100 KB
testcase_05 AC 25 ms
26,896 KB
testcase_06 AC 24 ms
24,836 KB
testcase_07 AC 24 ms
26,760 KB
testcase_08 AC 23 ms
25,032 KB
testcase_09 AC 24 ms
27,140 KB
testcase_10 AC 24 ms
25,100 KB
testcase_11 AC 24 ms
27,148 KB
testcase_12 AC 22 ms
24,716 KB
testcase_13 AC 24 ms
24,844 KB
testcase_14 AC 24 ms
25,132 KB
testcase_15 AC 24 ms
24,856 KB
testcase_16 AC 25 ms
26,764 KB
testcase_17 AC 24 ms
24,848 KB
testcase_18 AC 24 ms
24,968 KB
testcase_19 AC 24 ms
25,008 KB
testcase_20 AC 24 ms
25,092 KB
testcase_21 AC 24 ms
24,880 KB
testcase_22 AC 24 ms
24,716 KB
testcase_23 AC 25 ms
24,712 KB
testcase_24 AC 331 ms
53,952 KB
testcase_25 AC 327 ms
56,096 KB
testcase_26 AC 324 ms
54,076 KB
testcase_27 AC 332 ms
54,104 KB
testcase_28 AC 334 ms
52,196 KB
testcase_29 AC 2,904 ms
81,712 KB
testcase_30 AC 2,692 ms
83,584 KB
testcase_31 AC 2,874 ms
85,856 KB
testcase_32 AC 2,675 ms
83,376 KB
testcase_33 AC 2,692 ms
83,792 KB
testcase_34 AC 2,650 ms
83,880 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;
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 y = 0; y < H; y++)
            for (int x = 0; x < W; x++)
            {
                if (map[y, x] == 0) continue;
                map[y, x] = 0;
                Pair P = new Pair(x, y);
                Q.Enqueue(P);
                while (Q.Count() != 0)
                {
                    Pair pos = Q.Dequeue();
                    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));
                        map[yy, xx] = 0;
                    }
                }
                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