結果

問題 No.697 池の数はいくつか
ユーザー 👑 rin204rin204
提出日時 2022-03-23 16:17:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,627 ms / 6,000 ms
コード長 1,050 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 205,044 KB
実行使用メモリ 38,528 KB
最終ジャッジ日時 2024-11-08 09:01:46
合計ジャッジ時間 14,882 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 2 ms
5,248 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 2 ms
5,248 KB
testcase_17 AC 2 ms
5,248 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 2 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 2 ms
5,248 KB
testcase_23 AC 2 ms
5,248 KB
testcase_24 AC 180 ms
7,168 KB
testcase_25 AC 182 ms
7,168 KB
testcase_26 AC 180 ms
7,296 KB
testcase_27 AC 180 ms
7,040 KB
testcase_28 AC 180 ms
7,168 KB
testcase_29 AC 1,627 ms
38,400 KB
testcase_30 AC 1,624 ms
38,400 KB
testcase_31 AC 1,627 ms
38,400 KB
testcase_32 AC 1,620 ms
38,400 KB
testcase_33 AC 1,612 ms
38,528 KB
testcase_34 AC 1,619 ms
38,400 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