結果

問題 No.697 池の数はいくつか
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-12 13:10:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 2,898 ms
コンパイル使用メモリ 115,220 KB
実行使用メモリ 461,992 KB
最終ジャッジ日時 2023-08-24 20:45:09
合計ジャッジ時間 18,812 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 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,384 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 170 ms
7,444 KB
testcase_25 AC 170 ms
7,424 KB
testcase_26 AC 170 ms
7,584 KB
testcase_27 AC 169 ms
7,724 KB
testcase_28 AC 169 ms
7,420 KB
testcase_29 MLE -
testcase_30 AC 1,588 ms
39,812 KB
testcase_31 MLE -
testcase_32 AC 1,526 ms
39,908 KB
testcase_33 AC 1,525 ms
39,856 KB
testcase_34 AC 1,523 ms
39,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>

using namespace std;

int H, W;

vector<vector<bool>> visit;
vector<vector<int>> field;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int h, int w){
    int nh, nw;

    visit[h][w] = 1;

    for (int dir=0; dir < 4; dir++){
        nh = h + dx[dir];
        nw = w + dy[dir];

        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (field[nh][nw] == 0) continue;
        if (visit[nh][nw]) continue;

        dfs(nh, nw);
    }
}

int main(){

    int ans=0;
    cin >> H >> W;
    field.resize(H, vector<int>(W));
    visit.resize(H, vector<bool>(W));

    for (int i=0; i < H; i++){
        for (int j=0; j<W; j++) cin >> field[i][j];
    }

    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            if (!visit[i][j] && field[i][j] == 1){
                ans++;
                dfs(i, j);
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0