結果

問題 No.697 池の数はいくつか
ユーザー daleksprinterdaleksprinter
提出日時 2018-09-08 01:23:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,748 ms / 6,000 ms
コード長 1,049 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 169,640 KB
実行使用メモリ 113,052 KB
最終ジャッジ日時 2024-04-25 20:18:36
合計ジャッジ時間 13,486 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 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,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 156 ms
7,380 KB
testcase_25 AC 163 ms
7,476 KB
testcase_26 AC 168 ms
7,324 KB
testcase_27 AC 160 ms
7,524 KB
testcase_28 AC 162 ms
7,444 KB
testcase_29 AC 1,722 ms
111,988 KB
testcase_30 AC 1,442 ms
38,704 KB
testcase_31 AC 1,748 ms
113,052 KB
testcase_32 AC 1,472 ms
38,600 KB
testcase_33 AC 1,436 ms
38,688 KB
testcase_34 AC 1,451 ms
38,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;

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

int main(){
    int h,w;
    cin >> h >> w;
    int arr[h][w];

    int ans = 0;

    rep(i,0,h){
        rep(j,0,w){
            cin >> arr[i][j];
        }

    }

    rep(i,0,h){
        rep(j,0,w){
        
            if(arr[i][j] == 1){
                stack<pair<int,int>> stk;
                stk.push(make_pair(i,j));
                

                while(!stk.empty()){
                    pair<int,int> tmp = stk.top();
                    arr[tmp.first][tmp.second] = 0;
                    stk.pop();
                    rep(k,0,4){
                        int y = tmp.first + dy[k];
                        int x = tmp.second + dx[k];
                        if(-1 < y && y < h && -1 < x && x < w && arr[y][x] == 1) stk.push(make_pair(y,x));
                    }
                }
                
                ans++;
            }
        }
    }
    cout << ans << endl;
}
0