結果

問題 No.697 池の数はいくつか
ユーザー munromunro
提出日時 2018-06-25 23:55:09
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 851 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 164,120 KB
実行使用メモリ 814,456 KB
最終ジャッジ日時 2024-05-04 06:03:24
合計ジャッジ時間 12,540 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 29 ms
38,528 KB
testcase_06 AC 27 ms
38,400 KB
testcase_07 AC 27 ms
38,528 KB
testcase_08 AC 27 ms
38,400 KB
testcase_09 AC 27 ms
38,528 KB
testcase_10 AC 27 ms
38,400 KB
testcase_11 AC 27 ms
38,528 KB
testcase_12 AC 27 ms
38,400 KB
testcase_13 AC 26 ms
38,528 KB
testcase_14 AC 27 ms
38,400 KB
testcase_15 AC 26 ms
38,528 KB
testcase_16 AC 26 ms
38,528 KB
testcase_17 AC 26 ms
38,400 KB
testcase_18 AC 27 ms
38,528 KB
testcase_19 AC 26 ms
38,528 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 120 ms
38,400 KB
testcase_25 RE -
testcase_26 AC 119 ms
38,528 KB
testcase_27 RE -
testcase_28 AC 121 ms
38,528 KB
testcase_29 RE -
testcase_30 MLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;
  cin >> H >> W;
  int A[3000][3000];
  int ans = 0;
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W; j++){
      cin >> A[i][j];
    }
  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W; j++){
      if(A[i][j]==0)continue; //0なら処理を飛ばす
      queue<pair<int,int>> q;
      q.push({i,j}); //queueに座標を保存

      while(!q.empty()){
	int X = q.front().first;
	int Y = q.front().second;
	q.pop();
	if(A[X][Y] == 0)continue; //0なら処理を飛ばす
        A[X][Y] = 0; //今の要素を0にする;
	q.push({X + 1,Y}); //queueに周りの座標を格納
        q.push({X - 1,Y});
        q.push({X,Y + 1});
        q.push({X,Y - 1});
      }
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
0