QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64476 | #4434. Lemurs | AmrMohameD | WA | 20ms | 5528kb | C++ | 2.5kb | 2022-11-24 21:17:50 | 2022-11-24 21:17:53 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define sc second
#define EPS 1e-9
const int N=1005*1005;
char a[N],b[N];
int n,m,k;
int dis[N];
int di[]={0,1,0,-1};
int dj[]={1,0,-1,0};
bool valid(int x,int y)
{
if(x>=0&&x<n&&y>=0&&y<m)return true;
return false;
}
int val(int x,int y)
{
return x*m+y;
}
pair<int,int> cord(int val)
{
return {val/m,val%m};
}
void dijkstra(char c)
{
for(int i = 0 ;i <= n*m;i++)dis[i]=1e9;
queue<pair<int,int>>s;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[val(i,j)]==c)
{
s.push({0,val(i,j)});
dis[val(i,j)]=0;
}
}
}
while(!s.empty())
{
pair<int,int> p = s.front();
s.pop();
pair<int,int>p2=cord(p.sc);
int x=p2.fi,y=p2.sc;
for(int i=0;i<4;i++)
{
if(valid(x+di[i],y+dj[i]))
{
int v=val(x+di[i],y+dj[i]);
if(dis[v]>dis[p.sc]+1)
{
dis[v]=dis[p.sc]+1;
s.push({dis[v],v});
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>m>>k;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[val(i,j)];
b[val(i,j)]=a[val(i,j)];
}
}
dijkstra('.');
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(dis[val(i,j)]>k)
{
a[val(i,j)]='X';
}
else
{
a[val(i,j)]='.';
}
}
}
dijkstra('X');
bool ok=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(b[val(i,j)]=='X')
{
if(dis[val(i,j)]>k)ok=0;
}
}
}
if(ok)
{
cout<<"TAK\n";
}
else
{
cout<<"NIE\n";
}
}
return 0;
}
/*
2
3 3 1
.XX
XXX
XX.
3 4 1
..XX
X.XX
X..X
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 20ms
memory: 5528kb
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 TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK ...
result:
wrong answer 6th lines differ - expected: 'NIE', found: 'TAK'