結果

問題 No.697 池の数はいくつか
ユーザー beetbeet
提出日時 2018-11-15 17:28:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,562 ms / 6,000 ms
コード長 1,109 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 202,248 KB
実行使用メモリ 75,148 KB
最終ジャッジ日時 2024-04-25 20:21:37
合計ジャッジ時間 14,222 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
40,196 KB
testcase_01 AC 10 ms
39,840 KB
testcase_02 AC 10 ms
40,620 KB
testcase_03 AC 10 ms
39,780 KB
testcase_04 AC 10 ms
40,408 KB
testcase_05 AC 10 ms
39,536 KB
testcase_06 AC 10 ms
40,856 KB
testcase_07 AC 10 ms
39,832 KB
testcase_08 AC 10 ms
39,960 KB
testcase_09 AC 9 ms
39,780 KB
testcase_10 AC 9 ms
40,740 KB
testcase_11 AC 10 ms
39,784 KB
testcase_12 AC 9 ms
39,584 KB
testcase_13 AC 10 ms
40,356 KB
testcase_14 AC 11 ms
39,780 KB
testcase_15 AC 10 ms
40,948 KB
testcase_16 AC 10 ms
41,452 KB
testcase_17 AC 9 ms
41,352 KB
testcase_18 AC 9 ms
40,992 KB
testcase_19 AC 10 ms
39,720 KB
testcase_20 AC 10 ms
40,308 KB
testcase_21 AC 9 ms
39,580 KB
testcase_22 AC 10 ms
40,504 KB
testcase_23 AC 10 ms
40,188 KB
testcase_24 AC 178 ms
52,240 KB
testcase_25 AC 172 ms
51,512 KB
testcase_26 AC 187 ms
51,672 KB
testcase_27 AC 189 ms
51,700 KB
testcase_28 AC 181 ms
51,884 KB
testcase_29 AC 1,432 ms
75,148 KB
testcase_30 AC 1,513 ms
75,024 KB
testcase_31 AC 1,482 ms
74,892 KB
testcase_32 AC 1,533 ms
74,892 KB
testcase_33 AC 1,562 ms
75,028 KB
testcase_34 AC 1,530 ms
75,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const int MAX = 3030;
int st[MAX][MAX],dp[MAX][MAX];
signed main(){
  int h,w;
  cin>>h>>w;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>st[i][j];
  memset(dp,0,sizeof(dp));
  int ans=0;

  auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};
  int dy[]={0,0,1,-1};
  int dx[]={1,-1,0,0};
  
  auto bfs=
    [&](int y,int x){
      using P = pair<int, int>;
      queue<P> q;
      q.emplace(y,x);
      dp[y][x]=1;
      while(!q.empty()){
        tie(y,x)=q.front();q.pop();
        for(int k=0;k<4;k++){
          int ny=y+dy[k],nx=x+dx[k];
          if(!in(ny,nx)||!st[ny][nx]) continue;
          if(dp[ny][nx]) continue;
          q.emplace(ny,nx);
          dp[ny][nx]=1;
        }
      }
      ans++;      
    };
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(st[i][j]&&!dp[i][j]) bfs(i,j);
  cout<<ans<<endl;
  return 0;
}
0