結果

問題 No.697 池の数はいくつか
ユーザー mocobtmocobt
提出日時 2018-06-10 23:29:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 654 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 65,668 KB
実行使用メモリ 741,852 KB
最終ジャッジ日時 2024-11-25 13:16:13
合計ジャッジ時間 13,194 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int H,W;
int A[3000][3000];

void dfs(int x, int y){
    if(A[y][x]==0) return;
    A[y][x] = 0;
    if(y+1<H  && A[y+1][x]==1) dfs(x,y+1);
    if(y-1>=0 && A[y-1][x]==1) dfs(x,y-1);
    if(x+1<W  && A[y][x+1]==1) dfs(x+1,y);
    if(x-1>=0 && A[y][x-1]==1) dfs(x-1,y);
}

void solve(){
    int res = 0;
    for(int j=0;j<H;j++){
        for(int i=0;i<W;i++){    
            if(A[j][i]==1){
                dfs(i,j);
                res++;
            }
        }
    }
    cout << res << endl;
}

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