結果

問題 No.697 池の数はいくつか
ユーザー Kutimoti_T
提出日時 2018-06-23 18:32:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 993 ms / 6,000 ms
コード長 742 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,196 ms
コンパイル使用メモリ 182,556 KB
実行使用メモリ 39,168 KB
最終ジャッジ日時 2026-05-08 14:04:18
合計ジャッジ時間 9,582 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int H,W;

int A[3030][3030];

int main(){
  cin >> H >> W;
  rep(i,1,H){
    rep(j,1,W){
      cin >> A[i][j];
    }
  }

  using P = pair<int,int>;
  int ans = 0;

  rep(i,1,H){
    rep(j,1,W){
      if(A[i][j] == 0) continue;
      queue<P> que;
      que.push({i,j});
      while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if(A[x][y] == 0) continue;
        A[x][y] = 0;
        que.push({x + 1,y});
        que.push({x - 1,y});
        que.push({x,y + 1});
        que.push({x,y - 1});
      }
      ans++;
    }
  }

  cout << ans << endl;
}
0