結果

問題 No.697 池の数はいくつか
ユーザー finefine
提出日時 2018-09-28 11:04:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 830 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 162,944 KB
実行使用メモリ 574,748 KB
最終ジャッジ日時 2024-04-25 20:20:02
合計ジャッジ時間 9,468 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 85 ms
6,940 KB
testcase_25 AC 83 ms
6,944 KB
testcase_26 AC 84 ms
7,080 KB
testcase_27 AC 83 ms
6,940 KB
testcase_28 AC 85 ms
6,940 KB
testcase_29 MLE -
testcase_30 AC 735 ms
12,284 KB
testcase_31 MLE -
testcase_32 AC 727 ms
12,372 KB
testcase_33 AC 733 ms
12,188 KB
testcase_34 AC 728 ms
12,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};

bool f[3005][3005];

void dfs(int ch, int cw) {
    f[ch][cw] = false;
    for (int i = 0; i < 4; i++) {
        int nh = ch + dh[i], nw = cw + dw[i];
        if (!f[nh][nw]) continue;
        f[nh][nw] = false;
        dfs(nh, nw);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> f[i][j];
        }
    }

    int ans = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (f[i][j]) {
                dfs(i, j);
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0