Submission #74286638


Source Code Expand

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

int main(){
  ll H,W,ans = 0,x,s,t;
  cin >> H >> W;
  vector<vector<char>> S(H,vector<char>(W));
  queue<pair<ll,ll>> BFS;
  for(ll i = 0;i < H;i++){
    for(ll j = 0;j < W;j++){
      cin >> S[i][j];
    }
  }
  for(ll i = 0;i < H;i++){
    for(ll j = 0;j < W;j++){
      if(S[i][j] == '#'){
        continue;
      }
      x = 1;
      BFS.push({i,j});
      S[i][j] = '#';
      while(BFS.size() > 0){
        s = BFS.front().first;
        t = BFS.front().second;
        if(s == 0 || s == H - 1 || t == 0 || t == W - 1){
          x = 0;
        }
        if(s - 1 >= 0 && S[s - 1][t] == '.'){
          BFS.push({s - 1,t});
          S[s - 1][t] = '#';
        }
        if(s + 1 < H && S[s + 1][t] == '.'){
          BFS.push({s + 1,t});
          S[s + 1][t] = '#';
        }
        if(t - 1 >= 0 && S[s][t - 1] == '.'){
          BFS.push({s,t - 1});
          S[s][t - 1] = '#';
        }
        if(t + 1 < W && S[s][t + 1] == '.'){
          BFS.push({s,t + 1});
          S[s][t + 1] = '#';
        }
        BFS.pop();
      }
      ans+=x;
    }
  }
  cout << ans;
}

Submission Info

Submission Time
Task C - Puddles
User MI6174
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1202 Byte
Status AC
Exec Time 36 ms
Memory 4668 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 24
Set Name Test Cases
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
Case Name Status Exec Time Memory
min.txt AC 1 ms 3464 KiB
random_01.txt AC 29 ms 4668 KiB
random_02.txt AC 9 ms 3900 KiB
random_03.txt AC 29 ms 4668 KiB
random_04.txt AC 15 ms 4132 KiB
random_05.txt AC 32 ms 4572 KiB
random_06.txt AC 2 ms 3464 KiB
random_07.txt AC 32 ms 4572 KiB
random_08.txt AC 2 ms 3592 KiB
random_09.txt AC 36 ms 4592 KiB
random_10.txt AC 26 ms 4336 KiB
random_11.txt AC 35 ms 4572 KiB
random_12.txt AC 1 ms 3620 KiB
random_13.txt AC 35 ms 4580 KiB
random_14.txt AC 3 ms 3684 KiB
random_15.txt AC 35 ms 4432 KiB
random_16.txt AC 11 ms 3948 KiB
random_17.txt AC 25 ms 4540 KiB
random_18.txt AC 31 ms 4668 KiB
random_19.txt AC 28 ms 4580 KiB
random_20.txt AC 28 ms 4580 KiB
random_21.txt AC 28 ms 4552 KiB
sample_01.txt AC 1 ms 3580 KiB
sample_02.txt AC 1 ms 3644 KiB