# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1023329 |
2024-07-14T15:48:36 Z |
snpmrnhlol |
Maze (JOI23_ho_t3) |
C++17 |
|
1 ms |
2396 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 3e3;
const int inf = 2e9;
int k,n,m,sx,sy,ex,ey;
int d[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
int v[N*N];
bool vis[N*N][2];
bool inbound(int x,int y){
return 0 <= x && x < n && 0 <= y && y < m;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int ans = inf;
cin>>n>>m>>k;
cin>>sx>>sy>>ex>>ey;
sx--;sy--;ex--;ey--;
vector <array<int,2>> q;
vector <array<int,4>> q2;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
char ch;
cin>>ch;
if(ch == '#'){
v[i*m + j] = 0;
}
}
}
vis[sx*m + sy][0] = 1;
int g = 0;
q.emplace_back(array<int,2>{sx,sy});
for(int i = 0;i <= n + m;i++){
int pt = 0;
q2.clear();
while(pt < q.size()){
auto x = q[pt];pt++;g++;
if(x[0] == ex && x[1] == ey){
ans = i;
}
///bfs
if(!vis[x[0]*m + x[1]][1]){
q2.emplace_back(array<int,4>{x[0],x[1],0,0});
}
for(int j = 0;j < 4;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(inbound(nx,ny) && !vis[nx*m + ny][0] && v[nx*m + ny] == 0){
vis[nx*m + ny][0] = 1;
q.emplace_back(array<int,2>{nx,ny});
}
}
}
q.clear();
pt = 0;
while(pt < q2.size()){
auto x = q2[pt];pt++;g++;
if(!vis[x[0]*m + x[1]][0]){
q.emplace_back(array<int,2>{x[0],x[1]});
vis[x[0]*m + x[1]][0] = 1;
}
if(x[2] != k - 1){
for(int j = 0;j < 2;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(inbound(nx,ny) && !vis[nx*m + ny][1]){
vis[nx*m + ny][1] = 1;
q2.emplace_back(array<int,4>{nx,ny,x[2] + 1,x[3]});
}
}
}
}
pt = 0;
while(pt < q2.size()){
auto x = q2[pt];pt++;g++;
if(!vis[x[0]*(m + 2) + x[1]][0]){
q.emplace_back(array<int,2>{x[0],x[1]});
vis[x[0]*(m + 2) + x[1]][0] = 1;
}
if(x[3] != k - 1){
for(int j = 2;j < 4;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(inbound(nx,ny) && !vis[nx*m + ny][1]){
vis[nx*m + ny][1] = 1;
q2.emplace_back(array<int,4>{nx,ny,x[2],x[3] + 1});
}
}
}
for(int j = 0;j < 4;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(inbound(nx,ny) && !vis[nx*m + ny][0]){
vis[nx*m + ny][0] = 1;
q.emplace_back(array<int,2>{nx,ny});
}
}
}
}
cout<<ans<<'\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | while(pt < q.size()){
| ~~~^~~~~~~~~~
Main.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(pt < q2.size()){
| ~~~^~~~~~~~~~~
Main.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | while(pt < q2.size()){
| ~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |