結果

問題 No.697 池の数はいくつか
ユーザー finefine
提出日時 2018-09-28 11:14:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 708 ms / 6,000 ms
コード長 991 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 169,420 KB
実行使用メモリ 85,660 KB
最終ジャッジ日時 2024-04-25 20:20:40
合計ジャッジ時間 8,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 77 ms
7,088 KB
testcase_25 AC 74 ms
7,888 KB
testcase_26 AC 77 ms
8,456 KB
testcase_27 AC 75 ms
7,796 KB
testcase_28 AC 75 ms
7,612 KB
testcase_29 AC 708 ms
85,660 KB
testcase_30 AC 685 ms
12,156 KB
testcase_31 AC 699 ms
85,536 KB
testcase_32 AC 660 ms
12,288 KB
testcase_33 AC 667 ms
12,236 KB
testcase_34 AC 671 ms
12,420 KB
権限があれば一括ダウンロードができます

ソースコード

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;
            s.emplace(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