結果

問題 No.697 池の数はいくつか
ユーザー roarisroaris
提出日時 2019-11-06 19:58:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 802 ms / 6,000 ms
コード長 1,119 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 169,668 KB
実行使用メモリ 76,244 KB
最終ジャッジ日時 2023-08-08 02:37:42
合計ジャッジ時間 9,331 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 92 ms
26,952 KB
testcase_25 AC 92 ms
26,952 KB
testcase_26 AC 92 ms
26,948 KB
testcase_27 AC 92 ms
26,936 KB
testcase_28 AC 93 ms
26,824 KB
testcase_29 AC 787 ms
76,068 KB
testcase_30 AC 796 ms
76,244 KB
testcase_31 AC 800 ms
76,116 KB
testcase_32 AC 796 ms
76,244 KB
testcase_33 AC 802 ms
76,184 KB
testcase_34 AC 796 ms
76,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int H, W;
int A[3100][3100];

void bfs(int sx, int sy) {
    A[sx][sy] = 1;
    queue<P> q;
    q.push(P(sx, sy));
    
    while (q.size()) {
        P p = q.front(); q.pop();
        int cx = p.first;
        int cy = p.second;
        
        for (int i=0; i<4; i++) {
            int nx = cx + dx[i];
            int ny = cy + dy[i];
            
            if (0<=nx && nx<H && 0<=ny && ny<W && A[nx][ny]==1) {
                A[nx][ny] = 0;
                q.push(P(nx, ny));
            }
        }
    }
    
    return;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> H >> W;
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> A[i][j];
        }
    }
    
    int ans = 0;
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (A[i][j] == 1) {
                ans++;
                bfs(i, j);
            }
        }
    }
    
    cout << ans << endl;
}
0