結果

問題 No.697 池の数はいくつか
ユーザー kyunakyuna
提出日時 2019-07-19 16:32:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 850 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 76,744 KB
実行使用メモリ 814,724 KB
最終ジャッジ日時 2023-08-16 23:08:30
合計ジャッジ時間 6,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,388 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 167 ms
7,320 KB
testcase_25 AC 167 ms
7,316 KB
testcase_26 AC 167 ms
7,304 KB
testcase_27 AC 167 ms
7,296 KB
testcase_28 AC 166 ms
7,492 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int ALIVE = 1, DEAD = 2;
int h, w;
vector<vector<int>> field;
bool out_field(int i, int j) { return i < 0 || i >= h || j < 0 || j >= w; }

void dfs(int i, int j) {
    field[i][j] = DEAD;
    for (int di: {-1, 0, 1}) for (int dj: {-1, 0, 1}) {
        if (di * di + dj * dj != 1) continue;
        int ni = i + di, nj = j + dj;
        if (out_field(ni, nj) || field[ni][nj] != ALIVE) continue;
        dfs(ni, nj);
    }
}

int main() {
    cin >> h >> w;
    field.assign(h, vector<int>(w));
    for (auto &row: field) for (auto &c: row) cin >> c;
    int cnt = 0;
    for (int si = 0; si < h; si++) for (int sj = 0; sj < w; sj++) {
        if (field[si][sj] != ALIVE) continue;
        cnt++;
        dfs(si, sj);
    }
    cout << cnt << endl;
    return 0;
}
0