#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
#define all(datastructure) datastructure.begin(),datastructure.end()
#define find(_vector , _data) upper_bound(_vector.begin(),_vector.end(),_data) - _vector.begin()
int numrow , numcol , k;
int sourcex , sourcey;
int sinkx , sinky;
struct _D
{
int x , y;
int stepx , stepy;
};
queue<_D> freezone , banzone;
const int dx[] = {0 , 0 , 1 , -1};
const int dy[] = {1 , -1 , 0 , 0};
bool Zone(int x , int y)
{
return x > 0 && x <= numrow && y > 0 && y <= numcol;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("text.inp","r",stdin);
// freopen("text.out","w",stdout);
cin >> numrow >> numcol >> k;
cin >> sourcex >> sourcey;
cin >> sinkx >> sinky;
vector<vector<char>> a(numrow+2,vector<char>(numcol+2));
vector<vector<int>> d(numrow+2,vector<int>(numcol+2,-1));
for (int i = 1; i <= numrow; ++i)
{
string s; cin >> s; s = '3' + s;
for (int j = 1; j <= numcol; ++j) d[i][j] = s[j];
}
if (a[sourcex][sourcey] == '.')
{
d[sourcex][sourcey] = 0;
freezone.push({sourcex,sourcey,0,0});
}
else
{
d[sourcex][sourcey] = 1;
banzone.push({sourcex,sourcey,k-1,k-1});
}
while (freezone.size() || banzone.size())
{
while (banzone.size())
{
_D node = banzone.front(); banzone.pop();
if (node.stepx == 0 || node.stepy == 0) freezone.push({node.x,node.y,0,0});
for (int i = 0; i < 4; ++i)
{
int u = node.x + dx[i];
int v = node.y + dy[i];
int remx = node.stepx - abs(dx[i]);
int remy = node.stepy - abs(dy[i]);
if ((remx>=0&&remy>=0) && Zone(u,v) && d[u][v] == -1)
{
d[u][v] = d[node.x][node.y];
banzone.push({u , v , remx , remy});
}
}
}
while (freezone.size())
{
_D node = freezone.front(); freezone.pop();
for (int i = 0; i < 4; ++i)
{
int u = node.x + dx[i];
int v = node.y + dy[i];
if (Zone(u,v) && d[u][v] == -1)
{
if (a[u][v] == '#')
{
banzone.push({u , v , k - 1 , k - 1});
d[u][v] = d[node.x][node.y] + 1;
}
else
{
freezone.push({u , v , 0 , 0});
d[u][v] = d[node.x][node.y];
}
}
}
}
}
cout << d[sinkx][sinky];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |