結果

問題 No.697 池の数はいくつか
ユーザー iqueue02iqueue02
提出日時 2019-11-26 23:09:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 815 ms / 6,000 ms
コード長 881 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 171,904 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-04-25 20:37:30
合計ジャッジ時間 9,288 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,948 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 90 ms
7,168 KB
testcase_25 AC 88 ms
7,168 KB
testcase_26 AC 89 ms
7,168 KB
testcase_27 AC 89 ms
7,296 KB
testcase_28 AC 88 ms
7,168 KB
testcase_29 AC 757 ms
38,784 KB
testcase_30 AC 812 ms
38,656 KB
testcase_31 AC 765 ms
38,912 KB
testcase_32 AC 815 ms
38,528 KB
testcase_33 AC 802 ms
38,528 KB
testcase_34 AC 805 ms
38,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int dy[] = {1,0,-1,0};
int dx[] = {0,1,0,-1};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h) rep(j,w) cin >> a[i][j];

  auto bfs = [&](int y, int x) {
    queue<P> que;
    que.push({y,x});
    a[y][x] = 0;
    while (!que.empty()) {
      P p = que.front(); que.pop();
      rep(i,4) {
        int ny = p.first + dy[i], nx = p.second + dx[i];
        if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
        if (a[ny][nx] == 0) continue;
        que.push({ny,nx});
        a[ny][nx] = 0;
      }
    }
  };
  int res = 0;
  rep(i,h) rep(j,w) if (a[i][j] == 1) bfs(i,j), res++;
  cout << res << endl;
  return 0;
}
0