結果

問題 No.697 池の数はいくつか
ユーザー m-44m-44
提出日時 2019-09-14 23:05:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,589 ms / 6,000 ms
コード長 803 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 169,648 KB
実行使用メモリ 38,716 KB
最終ジャッジ日時 2023-08-08 02:34:38
合計ジャッジ時間 14,125 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 172 ms
15,096 KB
testcase_25 AC 171 ms
15,008 KB
testcase_26 AC 172 ms
15,104 KB
testcase_27 AC 171 ms
15,084 KB
testcase_28 AC 172 ms
15,008 KB
testcase_29 AC 1,589 ms
38,664 KB
testcase_30 AC 1,518 ms
38,496 KB
testcase_31 AC 1,586 ms
38,704 KB
testcase_32 AC 1,520 ms
38,552 KB
testcase_33 AC 1,517 ms
38,528 KB
testcase_34 AC 1,518 ms
38,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int h, w;
int a[3000][3000];

void bfs(int sy, int sx) {
  queue<pair<int, int> > que;
  que.push(make_pair(sy, sx));
  while (!que.empty()) {
    int y = que.front().first;
    int x = que.front().second;
    que.pop();
    if (a[y][x] == 0) {
      continue;
    }
    a[y][x] = 0;
    if (y > 0) que.push(make_pair(y-1, x));
    if (y < h-1) que.push(make_pair(y+1, x));
    if (x > 0) que.push(make_pair(y, x-1));
    if (x < w-1) que.push(make_pair(y, x+1));
  }
}

int main() {
  cin>>h>>w;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin>>a[i][j];
    }
  }
  int cnt = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (a[i][j] == 1) {
        ++cnt;
        bfs(i, j);
      }
    }
  }
  cout<<cnt<<endl;
}
0