Submission #74279308


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(x) ((int)x.size())
ll ksm(ll a,ll b,ll p){if (p == 1)return 0;if (b == 0)return 1%p;
ll ans = 1;	a %= p;while (b > 0){if (b&1){ans = ans*a%p;}a = (a*a)
%p;b >>= 1;}return ans;}
const int mod = 1e9+7;
const int P = 998244353;
const ll inf = (1LL << 50LL);
const ll N = 5010;

const int D[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int h,w,ans = 0;
bool dist[1010][1010];
char s[1010][1010];
inline void dfs(int x,int y){
	dist[x][y] = true;
	for (int i = 0;i < 4;i++){
		int nx = x+D[i][0],ny = y+D[i][1];
		if (!dist[nx][ny] && s[nx][ny] == '.'){
			dfs(nx,ny);
		}
	}
}
int main(){
	scanf("%d%d",&h,&w);
	for (int i = 1;i <= h;i++){
		scanf("%s",s[i]+1);
	}
	for (int i = 0;i <= h+1;i++){
		for (int j = 0;j <= w+1;j++){
			if (i <= 0 || i > h || j <= 0 || j > w){
				s[i][j] = '.';
			}
		}
	}
	dfs(0,0);
	for (int i = 1;i <= h;i++){
		for (int j = 1;j <= w;j++){
			if (s[i][j] == '.' && !dist[i][j]){
				ans++;
				dfs(i,j);
			} 
		}
	}
	printf("%d",ans);
	
    return 0;
}

Submission Info

Submission Time
Task C - Puddles
User wuqize
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1255 Byte
Status AC
Exec Time 25 ms
Memory 37128 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 3784 KiB
random_01.txt AC 7 ms 6000 KiB
random_02.txt AC 3 ms 4576 KiB
random_03.txt AC 7 ms 5964 KiB
random_04.txt AC 4 ms 5380 KiB
random_05.txt AC 13 ms 5960 KiB
random_06.txt AC 1 ms 3812 KiB
random_07.txt AC 13 ms 5884 KiB
random_08.txt AC 1 ms 3972 KiB
random_09.txt AC 20 ms 6608 KiB
random_10.txt AC 15 ms 6524 KiB
random_11.txt AC 20 ms 6828 KiB
random_12.txt AC 1 ms 3820 KiB
random_13.txt AC 25 ms 18348 KiB
random_14.txt AC 3 ms 5728 KiB
random_15.txt AC 24 ms 18376 KiB
random_16.txt AC 8 ms 8528 KiB
random_17.txt AC 3 ms 5884 KiB
random_18.txt AC 23 ms 37128 KiB
random_19.txt AC 5 ms 5960 KiB
random_20.txt AC 13 ms 21260 KiB
random_21.txt AC 13 ms 21328 KiB
sample_01.txt AC 1 ms 3684 KiB
sample_02.txt AC 1 ms 3708 KiB