結果

問題 No.697 池の数はいくつか
ユーザー fine
提出日時 2018-09-28 11:14:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 171,104 KB
実行使用メモリ 12,328 KB
最終ジャッジ日時 2024-11-25 14:20:09
合計ジャッジ時間 9,360 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 5 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

bool f[3005][3005];

void dfs(int ch, int cw) {
    stack<P> s;
    s.emplace(ch, cw);
    while (!s.empty()) {
        P p = s.top();
        s.pop();
        f[p.first][p.second] = false;
        for (int i = 0; i < 4; i++) {
            int nh = p.first + dh[i], nw = p.second + dw[i];
            if (!f[nh][nw]) continue;
        }
    }
}

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