結果

問題 No.697 池の数はいくつか
ユーザー Manuel1024Manuel1024
提出日時 2021-07-10 02:26:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,623 ms / 6,000 ms
コード長 1,268 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 79,924 KB
実行使用メモリ 74,112 KB
最終ジャッジ日時 2024-04-25 21:05:25
合計ジャッジ時間 13,314 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 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 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 174 ms
11,520 KB
testcase_25 AC 183 ms
11,520 KB
testcase_26 AC 179 ms
11,520 KB
testcase_27 AC 174 ms
11,520 KB
testcase_28 AC 172 ms
11,648 KB
testcase_29 AC 1,586 ms
73,984 KB
testcase_30 AC 1,579 ms
73,728 KB
testcase_31 AC 1,582 ms
74,112 KB
testcase_32 AC 1,623 ms
73,856 KB
testcase_33 AC 1,595 ms
73,728 KB
testcase_34 AC 1,604 ms
73,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using P = pair<int, int>;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> s(h, vector<int>(w));
    for(auto &p: s){
        for(auto &pp: p) cin >> pp;
    }

    vector<vector<int>> visited(h, vector<int>(w, -1));
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == 1 && visited[i][j] == -1){
                queue<P> Q;
                Q.push(make_pair(i, j));
                visited[i][j] = ans;
                while(Q.size()){
                    auto cur = Q.front(); Q.pop();
                    for(int k = 0; k < 4; k++){
                        int nx = cur.first+dx[k];
                        int ny = cur.second+dy[k];
                        if(0 <= nx && nx < h
                        && 0 <= ny && ny < w
                        && s[nx][ny] == 1 && visited[nx][ny] == -1){
                            visited[nx][ny] = ans;
                            Q.push(make_pair(nx, ny));
                        }
                    }
                }
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}
0