QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672713 | #4434. Lemurs | kirco | TL | 809ms | 8688kb | C++23 | 2.7kb | 2024-10-24 18:23:20 | 2024-10-24 18:23:21 |
Judging History
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;
//继续扩展...
queue<pair<int,int>> tq;
vector<vector<bool>> tvis(n+1,vector<bool>(m+1,false));
tq.push({x,y});tvis[x][y]=true;
while(!tq.empty()){
auto& [tx,ty]=tq.front();
tq.pop();
use[tx][ty]=1;
for(int i=0;i<4;i++){
int tnx=tx+dx[i],tny=ty+dy[i];
if(pd(tnx,tny)&&abs(tnx-x)+abs(tny-y)<=k&&!tvis[tnx][tny]){
tvis[tnx][tny]=1;
tq.push({tnx,tny});
}
}
}
}
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(pd(nx,ny)&&!vis1[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';
//...
queue<pair<int,int>> tq;
vector<vector<bool>> tvis(n+1,vector<bool>(m+1,false));
tq.push({x,y});tvis[x][y]=true;
while(!tq.empty()){
auto& [tx,ty]=tq.front();
tq.pop();
ans[tx][ty]='x';
for(int i=0;i<4;i++){
int tnx=tx+dx[i],tny=ty+dy[i];
if(pd(tnx,tny)&&abs(tnx-x)+abs(tny-y)<=k&&!tvis[tnx][tny]){
tvis[tnx][tny]=1;
tq.push({tnx,tny});
}
}
}
}
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(pd(nx,ny)&&!vis2[nx][ny]){
vis2[nx][ny]=1;
q.push({nx,ny});
}
}
}
}
void solve(){
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");
//清空多测
memset(vis1,0,sizeof(vis1));
memset(vis2,0,sizeof(vis2));
memset(use,0,sizeof(use));
memset(ans,'B',sizeof(ans));
}
signed main()
{
iosy;
int _t=1;
cin>>_t;
while(_t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 809ms
memory: 8688kb
input:
4000 1 1 1 . 1 1 1 x 1 1 1000 . 1 1 1000 x 1 1000 4 ..........................................xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
TAK TAK TAK TAK TAK NIE NIE TAK NIE TAK NIE NIE TAK TAK NIE TAK TAK NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK NIE NIE TAK TAK TAK NIE NIE NIE TAK TAK NIE NIE TAK NIE NIE NIE TAK NIE NIE NIE TAK NIE NIE NIE NIE TAK NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK NIE NIE NIE TAK TAK ...
result:
ok 4000 lines
Test #2:
score: -100
Time Limit Exceeded
input:
36 1000 1000 2 ....xxxx..............xxxxxx..........xx..xxxx......xxxxxxxxxxx.........xxxxxxxxxx...xxxxxx....xxxxxx.......xxxxxx....xxxxxx......................................xx.............xxxxxxxxx......xxxxxxx................xxxxxx..xxxxxx....xxxxxx..............xxxxxxxxxxxxxxxxxxxxxxxxxxxx...x...