結果

問題 No.697 池の数はいくつか
ユーザー 👑 rin204rin204
提出日時 2022-03-23 16:17:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,483 ms / 6,000 ms
コード長 1,050 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 201,824 KB
実行使用メモリ 38,572 KB
最終ジャッジ日時 2024-04-25 21:07:49
合計ジャッジ時間 13,701 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 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 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 167 ms
7,140 KB
testcase_25 AC 164 ms
7,144 KB
testcase_26 AC 166 ms
7,104 KB
testcase_27 AC 168 ms
7,284 KB
testcase_28 AC 166 ms
7,112 KB
testcase_29 AC 1,439 ms
38,564 KB
testcase_30 AC 1,483 ms
38,516 KB
testcase_31 AC 1,441 ms
38,396 KB
testcase_32 AC 1,469 ms
38,396 KB
testcase_33 AC 1,470 ms
38,328 KB
testcase_34 AC 1,464 ms
38,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int di[4] = {0, 1, 0, -1};
int dj[4] = {1, 0, -1, 0};
int main(void){
    int h, w;
    cin >> h >> w;
    vector<int> A(h * w);
    for(int i = 0; i < h * w; i++) cin >> A[i];
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if (A[i * w + j] == 0) continue;
            A[i * w + j] = 0;
            ans++;
            queue<int> que;
            que.push(i * w + j);
            while(!que.empty()){
                int tmp = que.front();
                que.pop();
                int ii = tmp / w;
                int jj = tmp - ii * w;
                for(int k = 0; k < 4; k++){
                    int ni = ii + di[k];
                    int nj = jj + dj[k];
                    if(ni == -1 || ni == h || nj == -1 || nj == w) continue;
                    if(A[ni * w + nj] == 0) continue;
                    A[ni * w + nj] = 0;
                    que.push(ni * w + nj);
                }
            }
        }
    }
    cout << ans << "\n";
}
0