結果

問題 No.697 池の数はいくつか
ユーザー kokatsukokatsu
提出日時 2021-10-26 19:03:23
言語 D
(dmd 2.107.1)
結果
MLE  
実行時間 -
コード長 1,148 bytes
コンパイル時間 4,826 ms
コンパイル使用メモリ 203,464 KB
実行使用メモリ 509,744 KB
最終ジャッジ日時 2023-09-04 14:40:43
合計ジャッジ時間 21,156 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2,367 ms
75,176 KB
testcase_25 AC 5,344 ms
205,004 KB
testcase_26 MLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct Grid {
    int x;
    int y;
}

void main() {
    int H, W;
    readf("%d %d\n", H, W);

    auto A = new int[][](H, W);
    foreach (i; 0 .. H) {
        A[i] = readln.chomp.split.to!(int[]);
    }

    auto move = [
        Grid(-1, 0),
        Grid(0, 1),
        Grid(1, 0),
        Grid(0, -1)
    ];

    int res;

    foreach (i; 0 .. H) {
        foreach (j; 0 .. W) {
            if (A[i][j] == 0) {
                continue;
            }

            ++res;

            Grid[] que;
            que ~= Grid(i, j);

            while (!que.empty) {
                auto f = que.front;
                que.popFront;

                A[f.x][f.y] = 0;

                foreach (m; move) {
                    auto next = f;
                    next.x += m.x, next.y += m.y;

                    if (next.x < 0 || next.x >= H || next.y < 0 || next.y >= W) {
                        continue;
                    }

                    if (A[next.x][next.y] == 0) {
                        continue;
                    }

                    que ~= next;
                }
            }
        }
    }

    res.writeln;
}
0