Submission #74288714


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;

int H,W;
bool dfs(int v,vector<vector<int>> G,vector<bool>&seen,bool &ok){
  if(seen[v])return ok;
  seen[v]=true;
  if(v%W==0 || (v-v%W)/W==0 || v%W==W-1 || (v-v%W)/W==H-1)ok=false;
  for(auto nv:G[v]){
    if(!dfs(nv,G,seen,ok))ok=false;
  }
  return ok;
  
  
}



int main(){
  cin>>H>>W;
  vector<string> S(H);
  vector<vector<int>>  G(H*W);
  
  rep(i,H){
    cin>>S[i];
    rep(j,W){
      
      if(S.at(i).at(j)=='.'){
        if(i>0 && S.at(i-1).at(j)=='.'){
          G[W*i+j].push_back(W*(i-1)+j);
          G[W*(i-1)+j].push_back(W*i+j);
        }
        if(j>0 && S[i].at(j-1)=='.'){
          G[W*i+j].push_back(W*i+j-1);
          G[W*i+j-1].push_back(W*i+j);
        }
      }
    }
  }
  
  //v%W==0 || (v-v%W)/W==0 || v%W==W-1 || (v-v%W)/W==W-1
  /*
  int v=68;
  cout <<v%W<<endl;
  cout <<(v-v%W)/W<<endl;
  cout <<v%W<<endl;
  cout <<(v-v%W)/W<<endl;
  */
  
  vector<bool>seen(H*W,false);
  int answer=0;
  rep(i,H){
    rep(j,W){
      if(S.at(i).at(j)=='.'&&  !seen[i*W+j]){
      
        bool ok=true;
        if(dfs(i*W+j,G,seen,ok)){
          answer++;
          //cout <<W*i+j<<' ';
          //cout <<i<<' '<<j<<endl;
        }
      }
    }
  }
  cout <<answer<<endl;
  //*/
  
  
  
}

Submission Info

Submission Time
Task C - Puddles
User delta2197
Language C++23 (GCC 15.2.0)
Score 0
Code Size 1409 Byte
Status TLE
Exec Time > 2000 ms
Memory > 1048576 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 2
AC × 5
TLE × 12
MLE × 7
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 3588 KiB
random_01.txt TLE > 2000 ms 195252 KiB
random_02.txt TLE > 2000 ms 75752 KiB
random_03.txt TLE > 2000 ms 357916 KiB
random_04.txt TLE > 2000 ms 110684 KiB
random_05.txt TLE > 2000 ms 602932 KiB
random_06.txt TLE > 2000 ms 33868 KiB
random_07.txt TLE > 2000 ms 485888 KiB
random_08.txt TLE > 2000 ms 54740 KiB
random_09.txt TLE > 2000 ms > 1048576 KiB
random_10.txt MLE 1745 ms > 1048576 KiB
random_11.txt TLE > 2000 ms > 1048576 KiB
random_12.txt AC 1506 ms 103852 KiB
random_13.txt MLE 1323 ms > 1048576 KiB
random_14.txt MLE 1578 ms > 1048576 KiB
random_15.txt TLE > 2000 ms > 1048576 KiB
random_16.txt MLE 1541 ms > 1048576 KiB
random_17.txt AC 24 ms 28768 KiB
random_18.txt MLE 1115 ms > 1048576 KiB
random_19.txt TLE > 2000 ms 52292 KiB
random_20.txt MLE 1042 ms > 1048576 KiB
random_21.txt MLE 1041 ms > 1048576 KiB
sample_01.txt AC 1 ms 3620 KiB
sample_02.txt AC 1 ms 3656 KiB