結果

問題 No.697 池の数はいくつか
ユーザー fine
提出日時 2018-09-28 11:04:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 830 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 166,032 KB
実行使用メモリ 574,848 KB
最終ジャッジ日時 2024-11-08 08:06:24
合計ジャッジ時間 10,658 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

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