結果

問題 No.697 池の数はいくつか
ユーザー ldsybldsyb
提出日時 2018-08-31 23:43:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,564 ms / 6,000 ms
コード長 1,081 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 170,168 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-25 20:17:45
合計ジャッジ時間 13,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 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,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 170 ms
7,564 KB
testcase_25 AC 173 ms
6,944 KB
testcase_26 AC 173 ms
7,624 KB
testcase_27 AC 169 ms
7,452 KB
testcase_28 AC 173 ms
7,784 KB
testcase_29 AC 1,564 ms
12,328 KB
testcase_30 AC 1,507 ms
12,292 KB
testcase_31 AC 1,518 ms
12,376 KB
testcase_32 AC 1,530 ms
12,204 KB
testcase_33 AC 1,513 ms
12,328 KB
testcase_34 AC 1,492 ms
12,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool a[3000][3000];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = 0, dd[] = {0, 1, 0, -1, 0};
    function<void(int, int)> f = [&](int x, int y) {
        queue<pair<int, int>> q;
        q.push({x, y});
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            if (!a[i][j]) {
                continue;
            }
            a[i][j] = false;
            for (int k = 0; k < 4; k++) {
                int ni = i + dd[k], nj = j + dd[k + 1];
                if (0 <= ni && ni < n && 0 <= nj && nj < m && a[ni][nj]) {
                    q.push({ni, nj});
                }
            }
        }
    };
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j]) {
                f(i, j);
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0