結果

問題 No.697 池の数はいくつか
ユーザー kk
提出日時 2020-09-02 15:17:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 698 ms / 6,000 ms
コード長 1,150 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 202,016 KB
実行使用メモリ 38,820 KB
最終ジャッジ日時 2024-04-25 20:52:37
合計ジャッジ時間 8,717 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 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 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 78 ms
14,872 KB
testcase_25 AC 78 ms
16,100 KB
testcase_26 AC 81 ms
16,724 KB
testcase_27 AC 79 ms
16,248 KB
testcase_28 AC 78 ms
15,124 KB
testcase_29 AC 669 ms
38,820 KB
testcase_30 AC 691 ms
38,580 KB
testcase_31 AC 677 ms
38,780 KB
testcase_32 AC 692 ms
38,656 KB
testcase_33 AC 698 ms
38,640 KB
testcase_34 AC 694 ms
38,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int h, w;
int bd[3000][3000];
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> bd[i][j];
  
  int cnt = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (bd[i][j]) {
        ++cnt;
        queue<pair<int, int> > q;
        q.emplace(i, j);
        bd[i][j] = 0;
        while (!q.empty()) {
          int y, x;
          tie(y, x) = q.front();
          q.pop();
          for (int k = 0; k < 4; k++) {
            int yt = y + dy[k];
            int xt = x + dx[k];
            if (yt < 0 || yt >= h) continue;
            if (xt < 0 || xt >= w) continue;
            if (bd[yt][xt]) {
              bd[yt][xt] = 0;
              q.emplace(yt, xt);
            }
          }
        }
      }
    }
  }

  cout << cnt << endl;
  
  return 0;
}
0