結果

問題 No.697 池の数はいくつか
ユーザー kokatsukokatsu
提出日時 2021-10-26 19:14:42
言語 D
(dmd 2.107.1)
結果
TLE  
実行時間 -
コード長 1,109 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 211,292 KB
実行使用メモリ 193,552 KB
最終ジャッジ日時 2023-09-04 14:42:05
合計ジャッジ時間 19,627 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std;

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 deltaX = [-1, 0, 1, 0], deltaY = [0, 1, 0, -1];

    int[] que;

    int res;

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

            ++res;

            que ~= i * W + j;

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

                int x = f / W;
                int y = f % W;

                A[x][y] = 0;

                foreach (dx, dy; zip(deltaX, deltaY)) {
                    auto nx = x, ny = y;
                    nx += dx, ny += dy;

                    if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
                        continue;
                    }

                    if (A[nx][ny] == 0) {
                        continue;
                    }

                    que ~= nx * W + ny;
                }
            }
        }
    }

    res.writeln;
}
0