結果

問題 No.697 池の数はいくつか
ユーザー ldsybldsyb
提出日時 2018-08-31 14:14:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 837 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 173,848 KB
実行使用メモリ 600,960 KB
最終ジャッジ日時 2024-05-04 06:08:48
合計ジャッジ時間 15,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 182 ms
7,424 KB
testcase_25 AC 182 ms
7,424 KB
testcase_26 AC 181 ms
7,424 KB
testcase_27 AC 182 ms
7,424 KB
testcase_28 AC 182 ms
7,296 KB
testcase_29 MLE -
testcase_30 AC 1,632 ms
38,528 KB
testcase_31 MLE -
testcase_32 AC 1,654 ms
38,528 KB
testcase_33 AC 1,639 ms
38,528 KB
testcase_34 AC 1,638 ms
38,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (auto &aa : a) {
        for (auto &aaa : aa) {
            cin >> aaa;
        }
    }
    int ans = 0, dd[] = {0, 1, 0, -1, 0};
    function<void(int, int)> f = [&](int x, int y) {
        if (a[x][y] != 1) {
            return;
        }
        a[x][y] = 2;
        for (int i = 0; i < 4; i++) {
            int nx = x + dd[i], ny = y + dd[i + 1];
            if (0 <= nx && nx < n && 0 <= ny && ny < m) {
                f(nx, ny);
            }
        }
    };
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == 1) {
                f(i, j);
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0