提出 #74291382


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int,int>;
vector<pii> dir = {
  {1, 0}, {-1, 0}, {0, 1}, {0, -1}
};

void solveA () {
 int n;
 cin >> n;
 for (int i = n; i >= 1; i --) {
  cout << i << ",";
 }
 cout << endl;
}

void solveB () {
  int n;
  cin >> n;
  auto maze = vector(n + 1, vector<int> (n + 1, -1));
  for (int i = 1; i < n; i ++) {
    for (int j = i + 1; j <= n; j ++) {
      cin >> maze[i][j];
    }
  }
  for (int i = 1; i < n; i ++) {
    for (int j = i + 1; j <= n; j ++) {
      for (int k = j + 1; j <= n; j ++) {
       if (maze[i][j] + maze[j][k] < maze[i][k]) {
        cout << "Yes" << endl;
        return;
       }
      }
    }
  }
  cout << "No" << endl;
}

void solveC () {
  int h, w;
  cin >> h >> w;
  int cnt = 0;
  auto maze = vector(h + 1, vector<char> (w + 1));
  auto vis = vector(h + 1, vector<int> (w + 1));
  for (int i = 1; i <= h; i ++) {
    for (int j = 1; j <= w; j ++ ){
      cin >> maze[i][j];
    }
  }
  // debug(maze);
  // debug(vis);
  auto bfs = [&] (int xi, int yi) -> int {
   queue<pii> que;
   que.push({xi, yi});
   vis[xi][yi] = 1;
   bool ok = false;
   while (!que.empty()) {
    auto [x, y] = que.front();
    que.pop();
    for (auto&[dx, dy] : dir) {
      int nx = x + dx, ny = y + dy;
      if (nx < 1 || nx > h || ny < 1 || ny > w) {
        ok = true;
        continue;
      }
      if (vis[nx][ny]) continue;
      if (maze[nx][ny] != '.') continue;
      que.push({nx, ny});
      vis[nx][ny] = 1;
    }
   }
   if (!ok) return 1;
   return 0;
  };
 
  for (int i = 1; i <= h; i ++) {
    for (int j = 1; j <= w; j ++) {
      if (maze[i][j] == '.' && !vis[i][j]) {
        cnt += bfs(i, j);
      }
    }
  }
  //  debug(vis);
  cout << cnt << endl;
}
int main () {
  cin.tie(0)->sync_with_stdio(0);
  solveC();
}

提出情報

提出日時
問題 C - Puddles
ユーザ PureMilk
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1921 Byte
結果 AC
実行時間 33 ms
メモリ 8640 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 24
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3456 KiB
random_01.txt AC 16 ms 8204 KiB
random_02.txt AC 5 ms 4816 KiB
random_03.txt AC 16 ms 8336 KiB
random_04.txt AC 8 ms 5896 KiB
random_05.txt AC 23 ms 8328 KiB
random_06.txt AC 1 ms 3748 KiB
random_07.txt AC 24 ms 8208 KiB
random_08.txt AC 2 ms 3820 KiB
random_09.txt AC 33 ms 8612 KiB
random_10.txt AC 24 ms 7256 KiB
random_11.txt AC 33 ms 8540 KiB
random_12.txt AC 1 ms 3552 KiB
random_13.txt AC 29 ms 8612 KiB
random_14.txt AC 3 ms 4004 KiB
random_15.txt AC 29 ms 8640 KiB
random_16.txt AC 10 ms 5284 KiB
random_17.txt AC 8 ms 8272 KiB
random_18.txt AC 18 ms 8556 KiB
random_19.txt AC 20 ms 8272 KiB
random_20.txt AC 15 ms 8220 KiB
random_21.txt AC 15 ms 8140 KiB
sample_01.txt AC 1 ms 3648 KiB
sample_02.txt AC 1 ms 3428 KiB