QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1209#527986#7733. Cool, It’s Yesterday Four Times MorewangmaruiStelorFailed.2024-11-20 14:41:362024-11-20 14:41:37

Details

Extra Test:

Accepted
time: 1ms
memory: 3848kb

input:

5
31 31
...............................
...............................
...............................
...............................
...............................
...............................
...............................
...............................
...............................
.......

output:

0
0
0
0
0

result:

ok 5 lines

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527986#7733. Cool, It’s Yesterday Four Times MoreStelorAC ✓2ms6888kbC++201.3kb2024-08-23 01:27:082024-08-23 01:27:09

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int n,m,id,ans,vis[N][N];
char s[N][N];
vector<pair<int,int>> se;
bool inmp(int x,int y)
{
	if(x>=1&&x<=n&&y>=1&&y<=m) return true;
	return false;
}
void dfs(int x,int y)
{
	se.push_back({x,y});
	vis[x][y]=id;
	for(int i=0;i<4;++i)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if(inmp(nx,ny)&&s[nx][ny]=='.'&&!vis[nx][ny])
		{
			dfs(nx,ny);
		}
	}
}
bool check(int px,int py)
{
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(vis[i][j]!=id&&s[i][j]=='.')
			{
				bool f=true;
				for(auto t:se)
				{
					int nx=i-px+t.first,ny=j-py+t.second;
					if(!inmp(nx,ny)||s[nx][ny]!='.') 
					{
						f=false;break;
					}
				}
				if(f) return false;
			}
			
		}
	}
	return true;
}
void solve()
{
	cin>>n>>m;
	id=0,ans=0;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j)
	{
		cin>>s[i][j];
		vis[i][j]=0;
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(!vis[i][j]&&s[i][j]=='.')
			{
				se.clear();
				++id;
				dfs(i,j);
				if(check(i,j))
				{
					ans=ans+(int)se.size();
				}
			}
		}
	}
	cout<<ans<<'\n';
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	int _;
	cin>>_;
	while(_--) solve();
	return 0;
}