提出 #74278695


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N=1e3+3;
int n,m,mp[N][N],ans;
bool vis[N][N];
inline void bfs(int stx,int sty){
	queue<pii>q;bool success=true;
	q.push(make_pair(stx,sty));
	while(q.size()){
		auto qwq=q.front();q.pop();
		int x=qwq.first,y=qwq.second;
		if(x==1||x==n||y==1||y==m)success=false;
		if(x-1>=1&&x-1<=n&&mp[x-1][y]==0&&vis[x-1][y]==0)q.push(make_pair(x-1,y)),vis[x-1][y]=1;
		if(x+1>=1&&x+1<=n&&mp[x+1][y]==0&&vis[x+1][y]==0)q.push(make_pair(x+1,y)),vis[x+1][y]=1;
		if(y-1>=1&&y-1<=m&&mp[x][y-1]==0&&vis[x][y-1]==0)q.push(make_pair(x,y-1)),vis[x][y-1]=1;
		if(y+1>=1&&y+1<=m&&mp[x][y+1]==0&&vis[x][y+1]==0)q.push(make_pair(x,y+1)),vis[x][y+1]=1;
	}
	if(success)ans++;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		string s;cin>>s;
		for(int j=1;j<=m;j++)mp[i][j]=s[j-1]=='#'?1:0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(mp[i][j]==0&&vis[i][j]==0)bfs(i,j);
		}
	}
	cout<<ans;
	return 0;
}

提出情報

提出日時
問題 C - Puddles
ユーザ kac17
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1069 Byte
結果 AC
実行時間 26 ms
メモリ 8624 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 3692 KiB
random_01.txt AC 12 ms 8412 KiB
random_02.txt AC 4 ms 5224 KiB
random_03.txt AC 11 ms 8416 KiB
random_04.txt AC 7 ms 7480 KiB
random_05.txt AC 19 ms 8588 KiB
random_06.txt AC 1 ms 3900 KiB
random_07.txt AC 18 ms 8556 KiB
random_08.txt AC 2 ms 3820 KiB
random_09.txt AC 26 ms 8412 KiB
random_10.txt AC 19 ms 8356 KiB
random_11.txt AC 25 ms 8580 KiB
random_12.txt AC 1 ms 3928 KiB
random_13.txt AC 22 ms 8556 KiB
random_14.txt AC 3 ms 6188 KiB
random_15.txt AC 22 ms 8612 KiB
random_16.txt AC 8 ms 5848 KiB
random_17.txt AC 3 ms 7528 KiB
random_18.txt AC 15 ms 8572 KiB
random_19.txt AC 16 ms 7532 KiB
random_20.txt AC 9 ms 8624 KiB
random_21.txt AC 9 ms 8548 KiB
sample_01.txt AC 1 ms 3672 KiB
sample_02.txt AC 1 ms 3688 KiB