QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#672568#4434. LemurskircoRE 0ms0kbC++232.2kb2024-10-24 17:30:162024-10-24 17:30:17

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 17:30:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-24 17:30:16]
  • 提交

answer

#include <bits/stdc++.h>
#define iosy ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1005;
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
int n,m,k;
vector<vector<char>> mp(N,vector<char>(N));
bool vis1[N][N],vis2[N][N],use[N][N];
char ans[N][N];

bool pd(int x,int y){//判断是否出图
	if(x<1||x>n||y<1||y>m)return false;
	return true;
}

void bfs1(int a,int b){//(1,1)
	queue<pair<int,int>> q;
	q.push({a,b});
	vis1[a][b]=1;
	while(!q.empty()){
		auto& [x,y]=q.front();
		q.pop();
		if(mp[x][y]=='.'){
			//.为中心扩展距离<=k,则use[i][j]=1;
			//use[x][y]=1;
			//继续扩展...
			for(int i=max(1,x-k);i<=min(n,x+k);i++){
				for(int j=max(1,y-k);j<=min(m,y+k);j++){
					if(pd(i,j)&&abs(i-x)+abs(j-y)<=k)use[i][j]=1;
				}
			}
		}
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(!vis1[nx][ny]&&pd(nx,ny)){
				vis1[nx][ny]=1;
				q.push({nx,ny});
			}
		}
	}
}

void bfs2(int a,int b){//(1,1)
	queue<pair<int,int>> q;
	q.push({a,b});
	vis2[a][b]=1;
	while(!q.empty()){
		auto& [x,y]=q.front();
		q.pop();
		if(!use[x][y]){//在可用的单元上方巢穴,并把觅食范围存到ans[i][j];
			//ans[x][y]='x';
			//继续把觅食范围k内的单元格设为ans[i][j]='x';
			//...
			for(int i=max(1,x-k);i<=min(n,x+k);i++){
				for(int j=max(1,y-k);j<=min(m,y+k);j++){
					if(pd(i,j)&&abs(i-x)+abs(j-y)<=k)ans[i][j]='x';
				}
			}
		}
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(!vis2[nx][ny]&&pd(nx,ny)){
				vis2[nx][ny]=1;
				q.push({nx,ny});
			}
		}
	}
}

void solve(){
	//清空多测
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ans[i][j]='B';
	cin>>n>>m>>k;//觅食范围是一个菱形
	for(int i=1;i<=n;i++){
		string s;cin>>s;s=" "+s;
		for(int j=1;j<=m;j++){
			mp[i][j]=s[j];
		}
	}
	bfs1(1,1);
	bfs2(1,1);
	bool ok=1;//假设可以
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(mp[i][j]=='x'&&ans[i][j]!='x'){
				ok=0;
				break;
			}
		}
	}
	cout<<(ok? "TAK\n":"NIE\n");
	//清空多测
	mp.clear();
	memset(vis1,0,sizeof(vis1));
	memset(vis2,0,sizeof(vis2));
	memset(use,0,sizeof(use));
}

signed main()
{
	iosy;
	int _t=1;
	cin>>_t;
	while(_t--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

4000
1 1 1
.
1 1 1
x
1 1 1000
.
1 1 1000
x
1 1000 4
..........................................xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:


result: