結果

問題 No.697 池の数はいくつか
ユーザー roarisroaris
提出日時 2019-11-06 19:54:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,672 ms / 6,000 ms
コード長 1,183 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 170,568 KB
実行使用メモリ 152,952 KB
最終ジャッジ日時 2023-08-08 02:36:45
合計ジャッジ時間 15,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
79,176 KB
testcase_01 AC 22 ms
79,280 KB
testcase_02 AC 21 ms
79,124 KB
testcase_03 AC 22 ms
79,064 KB
testcase_04 AC 21 ms
79,068 KB
testcase_05 AC 22 ms
79,184 KB
testcase_06 AC 21 ms
79,100 KB
testcase_07 AC 22 ms
79,068 KB
testcase_08 AC 22 ms
79,244 KB
testcase_09 AC 22 ms
79,116 KB
testcase_10 AC 21 ms
79,100 KB
testcase_11 AC 23 ms
79,188 KB
testcase_12 AC 22 ms
79,104 KB
testcase_13 AC 22 ms
79,100 KB
testcase_14 AC 21 ms
79,284 KB
testcase_15 AC 21 ms
79,176 KB
testcase_16 AC 22 ms
79,064 KB
testcase_17 AC 22 ms
79,364 KB
testcase_18 AC 22 ms
79,364 KB
testcase_19 AC 22 ms
79,068 KB
testcase_20 AC 22 ms
79,172 KB
testcase_21 AC 22 ms
79,068 KB
testcase_22 AC 22 ms
79,380 KB
testcase_23 AC 22 ms
79,072 KB
testcase_24 AC 209 ms
103,992 KB
testcase_25 AC 210 ms
103,736 KB
testcase_26 AC 218 ms
103,696 KB
testcase_27 AC 208 ms
103,628 KB
testcase_28 AC 210 ms
103,644 KB
testcase_29 AC 1,611 ms
152,952 KB
testcase_30 AC 1,672 ms
152,776 KB
testcase_31 AC 1,588 ms
152,936 KB
testcase_32 AC 1,672 ms
152,908 KB
testcase_33 AC 1,670 ms
152,800 KB
testcase_34 AC 1,664 ms
152,832 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];
int visited[3100][3100];

void bfs(int sx, int sy) {
    visited[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 && visited[nx][ny]==0) {
                visited[nx][ny] = 1;
                q.push(P(nx, ny));
            }
        }
    }
    
    return;
}

signed main() {
    cin >> H >> W;
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> A[i][j];
        }
    }
    
    int ans = 0;
    memset(visited, 0, sizeof(visited));
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (A[i][j]==1 && visited[i][j]==0) {
                ans++;
                bfs(i, j);
            }
        }
    }
    
    cout << ans << endl;
}
0