結果

問題 No.697 池の数はいくつか
ユーザー mkawa2mkawa2
提出日時 2020-01-23 16:46:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,396 ms / 6,000 ms
コード長 978 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 167,828 KB
実行使用メモリ 77,772 KB
最終ジャッジ日時 2023-08-08 02:39:56
合計ジャッジ時間 12,849 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 158 ms
7,496 KB
testcase_25 AC 158 ms
7,416 KB
testcase_26 AC 158 ms
7,536 KB
testcase_27 AC 158 ms
7,728 KB
testcase_28 AC 158 ms
7,424 KB
testcase_29 AC 1,348 ms
77,772 KB
testcase_30 AC 1,395 ms
12,148 KB
testcase_31 AC 1,376 ms
77,524 KB
testcase_32 AC 1,389 ms
12,140 KB
testcase_33 AC 1,396 ms
12,200 KB
testcase_34 AC 1,394 ms
12,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
const ll inf = 1e16;
const ll md = 1000000007;

bool a[3005][3005];
int h,w;

void bfs(int i,int j){
  vector<pair<int,int>> stack;
  stack.emplace_back(i,j);
  while(stack.size()){
    i=stack.back().first;
    j=stack.back().second;
    stack.pop_back();
    rep(ij,2) rep(pm,2){
      int ni=i+(pm*2-1)*ij;
      int nj=j+(pm*2-1)*(1-ij);
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      if(a[ni][nj]==false) continue;
      a[ni][nj]=false;
      stack.emplace_back(ni,nj);
    }
  }
}

int main() {
  cin>>h>>w;
  rep(i,h) rep(j,w){
    int aij;
    cin>>aij;
    a[i][j]=(aij==1);
    }
  int ans=0;
  rep(i,h) rep(j,w){
    if(a[i][j]==false) continue;
    a[i][j]=false;
    bfs(i,j);
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}
0