# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1023263 |
2024-07-14T14:24:46 Z |
snpmrnhlol |
Maze (JOI23_ho_t3) |
C++17 |
|
158 ms |
282320 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 6e6;
const int inf = 2e9;
vector <char> v[N + 2];
vector <vector<bool>> vis[N + 2];
int k,n,m,sx,sy,ex,ey;
array<int,2> q[N + 5];
array<int,3> q2[N + 5];
array<int,3> q3[N + 5];
int d[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int ans = inf;
cin>>n>>m>>k;
cin>>sx>>sy>>ex>>ey;
for(int i = 0;i < n + 2;i++){
v[i].assign(m + 2,0);
vis[i].assign(m + 2,vector<bool>(3,0));
v[i][0] = 2;
v[i][m + 1] = 2;
}
for(int i = 0;i < m + 2;i++){
v[0][i] = 2;
v[n + 1][i] = 2;
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
char ch;
cin>>ch;
if(ch == '.'){
v[i + 1][j + 1] = 0;
}else{
v[i + 1][j + 1] = 1;
}
}
}
vis[sx][sy][0] = 1;
int pt = 0,sz = 0;
int pt2 = 0,sz2 = 0;
int pt3 = 0,sz3 = 0;
q[sz++] = {sx,sy};
for(int i = 0;i <= n + m;i++){
while(pt < sz){
auto x = q[pt];pt++;
//cout<<x[0]<<' '<<x[1]<<' '<<i<<'\n';
if(x[0] == ex && x[1] == ey){
ans = i;
}
///bfs
if(!vis[x[0]][x[1]][1]){
q2[sz2++] = {x[0],x[1],0};
}
for(int j = 0;j < 4;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(!vis[nx][ny][0] && v[nx][ny] == 0){
vis[nx][ny][0] = 1;
q[sz++] = {nx,ny};
}
}
}
while(pt2 < sz2){
auto x = q2[pt2];
pt2++;
if(!vis[x[0]][x[1]][2]){
q3[sz3++] = {x[0],x[1],0};
vis[x[0]][x[1]][2] = 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(!vis[nx][ny][1] && v[nx][ny] != 2){
vis[nx][ny][1] = 1;
q2[sz2++] = {nx,ny,x[2] + 1};
}
}
}
}
while(pt3 < sz3){
auto x = q3[pt3];
pt3++;
if(!vis[x[0]][x[1]][0]){
q[sz++] = {x[0],x[1]};
vis[x[0]][x[1]][0] = 1;
}
if(x[2] != k){
for(int j = 2;j < 4;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(!vis[nx][ny][2] && v[nx][ny] != 2){
vis[nx][ny][2] = 1;
q3[sz3++] = {nx,ny,x[2] + 1};
}
}
for(int j = 0;j < 2;j++){
int nx = x[0] + d[j][0];
int ny = x[1] + d[j][1];
if(!vis[nx][ny][0] && v[nx][ny] != 2){
vis[nx][ny][0] = 1;
q[sz++] = {nx,ny};
}
}
}
}
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
282196 KB |
Output is correct |
2 |
Correct |
121 ms |
282168 KB |
Output is correct |
3 |
Incorrect |
126 ms |
282320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
282196 KB |
Output is correct |
2 |
Correct |
117 ms |
282184 KB |
Output is correct |
3 |
Correct |
116 ms |
282192 KB |
Output is correct |
4 |
Correct |
158 ms |
282060 KB |
Output is correct |
5 |
Incorrect |
122 ms |
282196 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
282036 KB |
Output is correct |
2 |
Correct |
123 ms |
282032 KB |
Output is correct |
3 |
Correct |
111 ms |
282192 KB |
Output is correct |
4 |
Correct |
121 ms |
282192 KB |
Output is correct |
5 |
Correct |
118 ms |
282196 KB |
Output is correct |
6 |
Correct |
124 ms |
282172 KB |
Output is correct |
7 |
Correct |
125 ms |
282192 KB |
Output is correct |
8 |
Incorrect |
120 ms |
282192 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
282196 KB |
Output is correct |
2 |
Correct |
117 ms |
282184 KB |
Output is correct |
3 |
Correct |
116 ms |
282192 KB |
Output is correct |
4 |
Correct |
158 ms |
282060 KB |
Output is correct |
5 |
Incorrect |
122 ms |
282196 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
282196 KB |
Output is correct |
2 |
Correct |
117 ms |
282184 KB |
Output is correct |
3 |
Correct |
116 ms |
282192 KB |
Output is correct |
4 |
Correct |
158 ms |
282060 KB |
Output is correct |
5 |
Incorrect |
122 ms |
282196 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
282196 KB |
Output is correct |
2 |
Correct |
121 ms |
282168 KB |
Output is correct |
3 |
Incorrect |
126 ms |
282320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
282196 KB |
Output is correct |
2 |
Correct |
121 ms |
282168 KB |
Output is correct |
3 |
Incorrect |
126 ms |
282320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
282196 KB |
Output is correct |
2 |
Correct |
121 ms |
282168 KB |
Output is correct |
3 |
Incorrect |
126 ms |
282320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |