結果

問題 No.697 池の数はいくつか
ユーザー kk
提出日時 2020-09-02 15:17:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 727 ms / 6,000 ms
コード長 1,150 bytes
コンパイル時間 3,042 ms
コンパイル使用メモリ 204,340 KB
実行使用メモリ 38,744 KB
最終ジャッジ日時 2023-08-08 02:53:14
合計ジャッジ時間 10,151 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 84 ms
14,988 KB
testcase_25 AC 83 ms
14,980 KB
testcase_26 AC 85 ms
14,908 KB
testcase_27 AC 83 ms
14,912 KB
testcase_28 AC 84 ms
14,916 KB
testcase_29 AC 693 ms
38,508 KB
testcase_30 AC 727 ms
38,472 KB
testcase_31 AC 691 ms
38,492 KB
testcase_32 AC 725 ms
38,532 KB
testcase_33 AC 727 ms
38,456 KB
testcase_34 AC 724 ms
38,744 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