結果

問題 No.697 池の数はいくつか
ユーザー mocobtmocobt
提出日時 2018-06-10 22:57:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 744 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 65,444 KB
実行使用メモリ 741,540 KB
最終ジャッジ日時 2024-05-04 05:41:07
合計ジャッジ時間 12,987 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 156 ms
15,976 KB
testcase_25 AC 154 ms
15,992 KB
testcase_26 AC 156 ms
16,016 KB
testcase_27 AC 152 ms
14,932 KB
testcase_28 AC 153 ms
15,996 KB
testcase_29 MLE -
testcase_30 AC 1,351 ms
38,572 KB
testcase_31 MLE -
testcase_32 AC 1,356 ms
38,624 KB
testcase_33 AC 1,357 ms
38,716 KB
testcase_34 AC 1,365 ms
38,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int H,W;
int A[3000][3000];

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

    nx=x-1; ny=y;
    if(nx>=0 && A[ny][nx]==1) dfs(nx,ny);

    nx=x+1; ny=y;
    if(nx<W && A[ny][nx]==1) dfs(nx,ny);
}

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