結果

問題 No.697 池の数はいくつか
ユーザー 萃罰萃罰
提出日時 2023-08-05 20:56:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,540 ms / 6,000 ms
コード長 1,117 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 173,692 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-23 17:24:18
合計ジャッジ時間 15,269 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 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,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 170 ms
7,552 KB
testcase_25 AC 174 ms
7,552 KB
testcase_26 AC 173 ms
7,424 KB
testcase_27 AC 172 ms
7,424 KB
testcase_28 AC 169 ms
7,552 KB
testcase_29 AC 1,499 ms
39,040 KB
testcase_30 AC 1,537 ms
38,528 KB
testcase_31 AC 1,502 ms
38,912 KB
testcase_32 AC 1,540 ms
38,528 KB
testcase_33 AC 1,539 ms
38,656 KB
testcase_34 AC 1,534 ms
38,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ba = pair<int,int>;
int main(){
    int h,w;
    cin >> h>>w;
    vector<vector<int>> gra(h);
    for(int i=0;i<h;i++){
        vector<int> g(w);
        for(int j=0;j<w;j++){
            cin >> g[j];
        }
        gra[i] = g;
    }
    queue<ba> que;
    int hou[4][2]= {{0,1},{1,0},{-1,0},{0,-1}};
    int ans = 0;
    for(int i = 0;i<h;i++){
        for(int j=0;j<w;j++){
            if (gra[i][j] == 0) continue;
            ba fi = {i,j};
            que.push(fi);
            gra[i][j] = 0;
            while(!que.empty()){
                ba pos = que.front();
                que.pop();
                for(int L =0;L<4;L++){
                    int x = hou[L][0]+pos.first;
                    int y = hou[L][1]+pos.second;
                    if(0<=x&&x<h&&0<=y&&y<w){
                        if(gra[x][y] == 0) continue;
                        gra[x][y] = 0;
                        ba pu = {x,y};
                        que.push(pu);
                    }
                }
            }
            ans++;
        }
    }
    cout << ans<<endl;
}
0