結果

問題 No.697 池の数はいくつか
ユーザー face4face4
提出日時 2018-06-09 17:55:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 868 ms / 6,000 ms
コード長 939 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 74,184 KB
実行使用メモリ 86,440 KB
最終ジャッジ日時 2024-04-25 19:53:00
合計ジャッジ時間 7,554 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 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,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 80 ms
6,940 KB
testcase_25 AC 87 ms
7,876 KB
testcase_26 AC 77 ms
7,988 KB
testcase_27 AC 81 ms
7,540 KB
testcase_28 AC 81 ms
7,672 KB
testcase_29 AC 868 ms
85,752 KB
testcase_30 AC 673 ms
12,204 KB
testcase_31 AC 818 ms
86,440 KB
testcase_32 AC 734 ms
12,220 KB
testcase_33 AC 678 ms
12,364 KB
testcase_34 AC 707 ms
12,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<stack>
using namespace std;

#define W 3000
#define H 3000

char mat[H+1][W+1];
int cnt = 0;
int h, w;

void floodFill(int i, int j){
    stack<pair<int,int>> S;
    S.push({i,j});

    while(!S.empty()){
        pair<int,int> p = S.top(); S.pop();
        int y = p.first;
        int x = p.second;
        mat[y][x] = '0';

        if(y != 0 && mat[y-1][x] == '1')    S.push({y-1,x});
        if(y != h-1 && mat[y+1][x] == '1')  S.push({y+1,x});
        if(x != 0 && mat[y][x-1] == '1')    S.push({y,x-1});
        if(x != w-1 && mat[y][x+1] == '1')  S.push({y,x+1});
    }

    cnt++;
}

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

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){ 
            if(mat[i][j]=='1')  floodFill(i,j);
        }
    }

    cout << cnt << endl;
    return 0;
}
0