結果

問題 No.697 池の数はいくつか
ユーザー magmag
提出日時 2020-06-24 07:15:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 808 ms / 6,000 ms
コード長 1,037 bytes
コンパイル時間 1,961 ms
コンパイル使用メモリ 173,324 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-04-25 20:48:26
合計ジャッジ時間 9,277 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 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 89 ms
7,296 KB
testcase_25 AC 89 ms
7,168 KB
testcase_26 AC 91 ms
7,296 KB
testcase_27 AC 89 ms
7,168 KB
testcase_28 AC 89 ms
7,168 KB
testcase_29 AC 792 ms
38,784 KB
testcase_30 AC 808 ms
38,528 KB
testcase_31 AC 795 ms
38,912 KB
testcase_32 AC 804 ms
38,528 KB
testcase_33 AC 799 ms
38,528 KB
testcase_34 AC 808 ms
38,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
https://yukicoder.me/problems/no/697

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  vector<vector<int>> hoge(h,vector<int>(w));
  rep(i,h)rep(j,w)cin>>hoge[i][j];
  //$B0\F0(B4$BJ}8~$N%Y%/%H%k(B
  int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
  int ans=0,x,y,xx,yy;
  rep(sy,h){
    rep(sx,w){
      if(hoge[sy][sx]==1){
        ans++;
        queue<pair<int,int>> que;
        que.push({sx,sy});
        hoge[sy][sx]=0;
        while(que.size()){
          x=que.front().first;
          y=que.front().second;
          que.pop();
          rep(i,4){
            xx=x+dx[i];
            yy=y+dy[i];
            if (0 <= xx and xx < w and 0 <= yy and yy < h) if (hoge[yy][xx] == 1) {
              que.push({xx,yy});
              hoge[yy][xx] = 0;
            }
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}
0