結果

問題 No.697 池の数はいくつか
ユーザー MSKMSK
提出日時 2018-10-03 08:52:29
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 867 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 62,388 KB
実行使用メモリ 813,896 KB
最終ジャッジ日時 2024-05-04 06:16:20
合計ジャッジ時間 8,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> field(90000001, 0);

void dfs(int row, int col, int H, int W) {
  field[row * W + col] = 0;
  if((row - 1 >= 0) && (field[(row - 1) * W + col] == 1)) {
    dfs(row - 1, col, H, W);
  }
  if((row + 1 < H) && (field[(row + 1) * W + col] == 1)) {
    dfs(row + 1, col, H, W);
  }
  if((col - 1 >= 0) && (field[row * W + col - 1] == 1)) {
    dfs(row, col - 1, H, W);
  }
  if((col + 1 < W) && (field[row * W + col + 1] == 1)) {
    dfs(row, col + 1, H, W);
  }
}

int main(void) {
  int H, W;
  cin >> H >> W;
  for(int i = 0; i < H * W; i++) {
    cin >> field[i];
  }
  int ans = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(1 == field[i * W + j]) {
        dfs(i, j, H, W);
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0