結果

問題 No.697 池の数はいくつか
ユーザー t98slidert98slider
提出日時 2022-12-22 04:30:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 822 ms / 6,000 ms
コード長 1,234 bytes
コンパイル時間 4,213 ms
コンパイル使用メモリ 175,740 KB
実行使用メモリ 6,108 KB
最終ジャッジ日時 2023-08-11 11:08:36
合計ジャッジ時間 9,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,500 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 92 ms
4,376 KB
testcase_25 AC 93 ms
4,380 KB
testcase_26 AC 92 ms
4,380 KB
testcase_27 AC 90 ms
4,376 KB
testcase_28 AC 92 ms
4,376 KB
testcase_29 AC 672 ms
5,884 KB
testcase_30 AC 813 ms
6,016 KB
testcase_31 AC 666 ms
5,888 KB
testcase_32 AC 822 ms
6,108 KB
testcase_33 AC 821 ms
6,064 KB
testcase_34 AC 814 ms
5,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, ans = 0, v;
    cin >> h >> w;
    vector<vector<bool>> A(h, vector<bool>(w)), B(h, vector<bool>(w));
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            cin >> v;
            A[y][x] = v;
        }
    }
    queue<pair<int,int>> nxt;
    for(int cy = 0; cy < h; cy++){
        for(int cx = 0; cx < w; cx++){
            if(B[cy][cx])continue;
            if(!A[cy][cx])continue;
            ans++;
            B[cy][cx] = true;
            nxt.emplace(cy, cx);
            while(!nxt.empty()){
                int y, x;
                tie(y, x) = nxt.front();
                nxt.pop();
                for(int i = 0; i < 4; i++){
                    int ny = y + (i == 0) - (i == 1);
                    int nx = x + (i == 2) - (i == 3);
                    if(ny < 0 || nx < 0 || ny >= h || nx >= w)continue;
                    if(B[ny][nx])continue;
                    if(A[ny][nx] ^ A[y][x])continue;
                    B[ny][nx] = true;
                    nxt.emplace(ny, nx);
                }
            }
        }
    }
    cout << ans << '\n';
}
0