結果

問題 No.697 池の数はいくつか
ユーザー mkawa2mkawa2
提出日時 2020-01-23 16:46:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,441 ms / 6,000 ms
コード長 978 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 168,908 KB
実行使用メモリ 78,892 KB
最終ジャッジ日時 2024-04-25 20:39:21
合計ジャッジ時間 13,109 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 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,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 158 ms
7,328 KB
testcase_25 AC 162 ms
6,944 KB
testcase_26 AC 167 ms
8,328 KB
testcase_27 AC 167 ms
7,028 KB
testcase_28 AC 167 ms
6,944 KB
testcase_29 AC 1,383 ms
78,892 KB
testcase_30 AC 1,430 ms
12,296 KB
testcase_31 AC 1,388 ms
77,884 KB
testcase_32 AC 1,441 ms
12,312 KB
testcase_33 AC 1,424 ms
12,396 KB
testcase_34 AC 1,432 ms
12,368 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