結果

問題 No.697 池の数はいくつか
ユーザー yuki00130
提出日時 2018-06-09 16:22:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 832 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 61,352 KB
実行使用メモリ 596,924 KB
最終ジャッジ日時 2024-11-25 12:27:30
合計ジャッジ時間 13,906 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int H,W;
bool A[10000][10000];

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

int solve(int y,int x){
    if (!A[y][x])
    {
        return 0;
    }
    A[y][x] = false;
    for (int k = 0; k < 4; k++)
    {
        int ny = y + dy[k];
        int nx = x + dx[k];
        if(0 <= ny && ny < H && 0 <= nx && nx < W){
            solve(ny, nx);
        }
    }
    return 1;
}

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

    int res = 0;
    for(int i = 0;i < H;i++)
    {
        for(int j = 0;j < W;j++)
        {
            res += solve(i,j);
        }
    }

    cout << res << endl;

    return 0;
}
0