#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define abcorz ios_base::sync_with_stdio(false);cin.tie(0);
const int INF=1e18;
int32_t main(){
abcorz;
int n,m,k;cin>>n>>m>>k;
vector<vector<int>> v(n+2,vector<int>(m+2,1));
vector<vector<int>> dis(n+2,vector<int>(m+2,INF));
int s1,s2;cin>>s1>>s2;
int t1,t2;cin>>t1>>t2;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;cin>>c;
v[i][j]=(c=='#');
}
}
vector<int> dx={-1,1,0,0},dy={0,0,-1,1};
priority_queue<pair<int,pair<int,int>>> pq;
dis[s1][s2]=0;
pq.push({0,{s1,s2}});
while(pq.size()){
auto[d,tmp]=pq.top();
pq.pop();
d=-d;
auto [s1,s2]=tmp;
if(d!=dis[s1][s2]){
continue;
}
for(int k=0;k<4;k++){
int t1=s1+dx[k];
int t2=s2+dy[k];
if(t1==0||t1==n+1||t2==0||t2==m+1){
continue;
}
if(dis[t1][t2]>dis[s1][s2]+v[s1][s2]+v[t1][t2]){
dis[t1][t2]=dis[s1][s2]+v[s1][s2]+v[t1][t2];
pq.push({-dis[t1][t2],{t1,t2}});
}
}
}
cout<<dis[t1][t2]/2<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
1504 KB |
Output is correct |
20 |
Correct |
3 ms |
3056 KB |
Output is correct |
21 |
Correct |
8 ms |
1528 KB |
Output is correct |
22 |
Correct |
10 ms |
1368 KB |
Output is correct |
23 |
Correct |
10 ms |
1488 KB |
Output is correct |
24 |
Correct |
4 ms |
3716 KB |
Output is correct |
25 |
Correct |
4 ms |
3780 KB |
Output is correct |
26 |
Correct |
12 ms |
1628 KB |
Output is correct |
27 |
Correct |
11 ms |
1628 KB |
Output is correct |
28 |
Correct |
9 ms |
1372 KB |
Output is correct |
29 |
Correct |
20 ms |
3032 KB |
Output is correct |
30 |
Correct |
6 ms |
2668 KB |
Output is correct |
31 |
Correct |
21 ms |
3004 KB |
Output is correct |
32 |
Correct |
24 ms |
2908 KB |
Output is correct |
33 |
Correct |
19 ms |
3028 KB |
Output is correct |
34 |
Correct |
9 ms |
8648 KB |
Output is correct |
35 |
Correct |
11 ms |
8648 KB |
Output is correct |
36 |
Correct |
27 ms |
3164 KB |
Output is correct |
37 |
Correct |
29 ms |
3248 KB |
Output is correct |
38 |
Correct |
22 ms |
2904 KB |
Output is correct |
39 |
Correct |
231 ms |
25604 KB |
Output is correct |
40 |
Correct |
27 ms |
3924 KB |
Output is correct |
41 |
Correct |
11 ms |
10740 KB |
Output is correct |
42 |
Correct |
30 ms |
3932 KB |
Output is correct |
43 |
Correct |
16 ms |
9128 KB |
Output is correct |
44 |
Correct |
100 ms |
17568 KB |
Output is correct |
45 |
Correct |
68 ms |
20084 KB |
Output is correct |
46 |
Correct |
232 ms |
25940 KB |
Output is correct |
47 |
Correct |
252 ms |
25628 KB |
Output is correct |
48 |
Correct |
224 ms |
25424 KB |
Output is correct |
49 |
Correct |
79 ms |
83924 KB |
Output is correct |
50 |
Correct |
72 ms |
84108 KB |
Output is correct |
51 |
Correct |
306 ms |
26484 KB |
Output is correct |
52 |
Correct |
286 ms |
25980 KB |
Output is correct |
53 |
Correct |
248 ms |
25828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
1504 KB |
Output is correct |
20 |
Correct |
3 ms |
3056 KB |
Output is correct |
21 |
Correct |
8 ms |
1528 KB |
Output is correct |
22 |
Correct |
10 ms |
1368 KB |
Output is correct |
23 |
Correct |
10 ms |
1488 KB |
Output is correct |
24 |
Correct |
4 ms |
3716 KB |
Output is correct |
25 |
Correct |
4 ms |
3780 KB |
Output is correct |
26 |
Correct |
12 ms |
1628 KB |
Output is correct |
27 |
Correct |
11 ms |
1628 KB |
Output is correct |
28 |
Correct |
9 ms |
1372 KB |
Output is correct |
29 |
Correct |
20 ms |
3032 KB |
Output is correct |
30 |
Correct |
6 ms |
2668 KB |
Output is correct |
31 |
Correct |
21 ms |
3004 KB |
Output is correct |
32 |
Correct |
24 ms |
2908 KB |
Output is correct |
33 |
Correct |
19 ms |
3028 KB |
Output is correct |
34 |
Correct |
9 ms |
8648 KB |
Output is correct |
35 |
Correct |
11 ms |
8648 KB |
Output is correct |
36 |
Correct |
27 ms |
3164 KB |
Output is correct |
37 |
Correct |
29 ms |
3248 KB |
Output is correct |
38 |
Correct |
22 ms |
2904 KB |
Output is correct |
39 |
Correct |
231 ms |
25604 KB |
Output is correct |
40 |
Correct |
27 ms |
3924 KB |
Output is correct |
41 |
Correct |
11 ms |
10740 KB |
Output is correct |
42 |
Correct |
30 ms |
3932 KB |
Output is correct |
43 |
Correct |
16 ms |
9128 KB |
Output is correct |
44 |
Correct |
100 ms |
17568 KB |
Output is correct |
45 |
Correct |
68 ms |
20084 KB |
Output is correct |
46 |
Correct |
232 ms |
25940 KB |
Output is correct |
47 |
Correct |
252 ms |
25628 KB |
Output is correct |
48 |
Correct |
224 ms |
25424 KB |
Output is correct |
49 |
Correct |
79 ms |
83924 KB |
Output is correct |
50 |
Correct |
72 ms |
84108 KB |
Output is correct |
51 |
Correct |
306 ms |
26484 KB |
Output is correct |
52 |
Correct |
286 ms |
25980 KB |
Output is correct |
53 |
Correct |
248 ms |
25828 KB |
Output is correct |
54 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
1504 KB |
Output is correct |
20 |
Correct |
3 ms |
3056 KB |
Output is correct |
21 |
Correct |
8 ms |
1528 KB |
Output is correct |
22 |
Correct |
10 ms |
1368 KB |
Output is correct |
23 |
Correct |
10 ms |
1488 KB |
Output is correct |
24 |
Correct |
4 ms |
3716 KB |
Output is correct |
25 |
Correct |
4 ms |
3780 KB |
Output is correct |
26 |
Correct |
12 ms |
1628 KB |
Output is correct |
27 |
Correct |
11 ms |
1628 KB |
Output is correct |
28 |
Correct |
9 ms |
1372 KB |
Output is correct |
29 |
Correct |
20 ms |
3032 KB |
Output is correct |
30 |
Correct |
6 ms |
2668 KB |
Output is correct |
31 |
Correct |
21 ms |
3004 KB |
Output is correct |
32 |
Correct |
24 ms |
2908 KB |
Output is correct |
33 |
Correct |
19 ms |
3028 KB |
Output is correct |
34 |
Correct |
9 ms |
8648 KB |
Output is correct |
35 |
Correct |
11 ms |
8648 KB |
Output is correct |
36 |
Correct |
27 ms |
3164 KB |
Output is correct |
37 |
Correct |
29 ms |
3248 KB |
Output is correct |
38 |
Correct |
22 ms |
2904 KB |
Output is correct |
39 |
Correct |
231 ms |
25604 KB |
Output is correct |
40 |
Correct |
27 ms |
3924 KB |
Output is correct |
41 |
Correct |
11 ms |
10740 KB |
Output is correct |
42 |
Correct |
30 ms |
3932 KB |
Output is correct |
43 |
Correct |
16 ms |
9128 KB |
Output is correct |
44 |
Correct |
100 ms |
17568 KB |
Output is correct |
45 |
Correct |
68 ms |
20084 KB |
Output is correct |
46 |
Correct |
232 ms |
25940 KB |
Output is correct |
47 |
Correct |
252 ms |
25628 KB |
Output is correct |
48 |
Correct |
224 ms |
25424 KB |
Output is correct |
49 |
Correct |
79 ms |
83924 KB |
Output is correct |
50 |
Correct |
72 ms |
84108 KB |
Output is correct |
51 |
Correct |
306 ms |
26484 KB |
Output is correct |
52 |
Correct |
286 ms |
25980 KB |
Output is correct |
53 |
Correct |
248 ms |
25828 KB |
Output is correct |
54 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
1504 KB |
Output is correct |
20 |
Correct |
3 ms |
3056 KB |
Output is correct |
21 |
Correct |
8 ms |
1528 KB |
Output is correct |
22 |
Correct |
10 ms |
1368 KB |
Output is correct |
23 |
Correct |
10 ms |
1488 KB |
Output is correct |
24 |
Correct |
4 ms |
3716 KB |
Output is correct |
25 |
Correct |
4 ms |
3780 KB |
Output is correct |
26 |
Correct |
12 ms |
1628 KB |
Output is correct |
27 |
Correct |
11 ms |
1628 KB |
Output is correct |
28 |
Correct |
9 ms |
1372 KB |
Output is correct |
29 |
Correct |
20 ms |
3032 KB |
Output is correct |
30 |
Correct |
6 ms |
2668 KB |
Output is correct |
31 |
Correct |
21 ms |
3004 KB |
Output is correct |
32 |
Correct |
24 ms |
2908 KB |
Output is correct |
33 |
Correct |
19 ms |
3028 KB |
Output is correct |
34 |
Correct |
9 ms |
8648 KB |
Output is correct |
35 |
Correct |
11 ms |
8648 KB |
Output is correct |
36 |
Correct |
27 ms |
3164 KB |
Output is correct |
37 |
Correct |
29 ms |
3248 KB |
Output is correct |
38 |
Correct |
22 ms |
2904 KB |
Output is correct |
39 |
Correct |
231 ms |
25604 KB |
Output is correct |
40 |
Correct |
27 ms |
3924 KB |
Output is correct |
41 |
Correct |
11 ms |
10740 KB |
Output is correct |
42 |
Correct |
30 ms |
3932 KB |
Output is correct |
43 |
Correct |
16 ms |
9128 KB |
Output is correct |
44 |
Correct |
100 ms |
17568 KB |
Output is correct |
45 |
Correct |
68 ms |
20084 KB |
Output is correct |
46 |
Correct |
232 ms |
25940 KB |
Output is correct |
47 |
Correct |
252 ms |
25628 KB |
Output is correct |
48 |
Correct |
224 ms |
25424 KB |
Output is correct |
49 |
Correct |
79 ms |
83924 KB |
Output is correct |
50 |
Correct |
72 ms |
84108 KB |
Output is correct |
51 |
Correct |
306 ms |
26484 KB |
Output is correct |
52 |
Correct |
286 ms |
25980 KB |
Output is correct |
53 |
Correct |
248 ms |
25828 KB |
Output is correct |
54 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |