結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,380 KB
testcase_01 AC 3 ms
5,440 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,408 KB
testcase_04 AC 2 ms
5,472 KB
testcase_05 AC 3 ms
5,388 KB
testcase_06 AC 2 ms
5,532 KB
testcase_07 AC 2 ms
5,440 KB
testcase_08 AC 2 ms
5,436 KB
testcase_09 AC 2 ms
5,580 KB
testcase_10 AC 3 ms
5,544 KB
testcase_11 AC 3 ms
5,452 KB
testcase_12 AC 2 ms
5,448 KB
testcase_13 AC 2 ms
5,472 KB
testcase_14 AC 2 ms
5,500 KB
testcase_15 AC 2 ms
5,364 KB
testcase_16 AC 2 ms
5,636 KB
testcase_17 AC 2 ms
5,396 KB
testcase_18 AC 2 ms
5,380 KB
testcase_19 AC 2 ms
5,604 KB
testcase_20 AC 2 ms
5,660 KB
testcase_21 AC 2 ms
5,400 KB
testcase_22 AC 2 ms
5,368 KB
testcase_23 AC 2 ms
5,540 KB
testcase_24 AC 97 ms
20,832 KB
testcase_25 AC 96 ms
20,816 KB
testcase_26 AC 95 ms
20,600 KB
testcase_27 AC 96 ms
20,736 KB
testcase_28 AC 96 ms
20,632 KB
testcase_29 MLE -
testcase_30 AC 800 ms
47,444 KB
testcase_31 MLE -
testcase_32 AC 800 ms
47,540 KB
testcase_33 AC 797 ms
47,452 KB
testcase_34 AC 790 ms
47,516 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