結果

問題 No.697 池の数はいくつか
ユーザー tokizotokizo
提出日時 2019-02-01 16:05:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 922 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 165,060 KB
実行使用メモリ 328,688 KB
最終ジャッジ日時 2023-08-16 23:01:35
合計ジャッジ時間 10,833 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,372 KB
testcase_01 AC 2 ms
5,436 KB
testcase_02 AC 2 ms
5,312 KB
testcase_03 AC 2 ms
5,420 KB
testcase_04 AC 2 ms
5,440 KB
testcase_05 AC 2 ms
5,368 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,444 KB
testcase_08 AC 2 ms
5,416 KB
testcase_09 AC 2 ms
5,444 KB
testcase_10 AC 2 ms
5,440 KB
testcase_11 AC 2 ms
5,320 KB
testcase_12 AC 2 ms
5,420 KB
testcase_13 AC 2 ms
5,340 KB
testcase_14 AC 2 ms
5,320 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,304 KB
testcase_17 AC 2 ms
5,500 KB
testcase_18 AC 2 ms
5,448 KB
testcase_19 AC 2 ms
5,448 KB
testcase_20 AC 2 ms
5,392 KB
testcase_21 AC 2 ms
5,456 KB
testcase_22 AC 2 ms
5,552 KB
testcase_23 AC 2 ms
5,380 KB
testcase_24 AC 108 ms
20,644 KB
testcase_25 AC 107 ms
20,672 KB
testcase_26 AC 108 ms
20,676 KB
testcase_27 AC 110 ms
20,668 KB
testcase_28 AC 108 ms
20,668 KB
testcase_29 MLE -
testcase_30 AC 916 ms
47,508 KB
testcase_31 MLE -
testcase_32 AC 917 ms
47,520 KB
testcase_33 AC 914 ms
47,376 KB
testcase_34 AC 910 ms
47,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int h, w;
const int MAX = 3010;
int A[MAX][MAX];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool seen[MAX][MAX];

void dfs(int x, int y){
    seen[x][y] = true;
    for(int i = 0; i < 4; i++){
        int nx, ny;
        nx = x + dx[i];
        ny = y + dy[i];
        if(nx < 0 or ny < 0 or nx >= h or ny >= w) continue;
        if(A[nx][ny] == 0 or seen[nx][ny]) continue;
        dfs(nx, ny);
    }
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> A[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(A[i][j] == 1){
                if(!seen[i][j]) ans++;
                dfs(i, j);
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0