#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
vector<string> arr;
int R,C,N;
pii s,e;
pii dir[] = {{0,1},{1,0},{0,-1},{-1,0}};
namespace N1{
vector<vector<int>> dist;
deque<pair<pii,int>> dq;
void GO(){
dist = vector<vector<int>>(R,vector<int>(C,R*C+1));
dist[s.fs][s.sc] = (arr[s.fs][s.sc] == '#');
dq.push_back(make_pair(s,dist[s.fs][s.sc]));
while(!dq.empty()){
auto now = dq.front().fs;
auto d = dq.front().sc;
dq.pop_front();
if(dist[now.fs][now.sc] != d)continue;
for(auto &dd:dir){
pii nxt = {now.fs+dd.fs,now.sc+dd.sc};
if(nxt.fs>=R||nxt.fs<0||nxt.sc>=C||nxt.sc<0)continue;
int w = (arr[nxt.fs][nxt.sc] == '#');
if(dist[nxt.fs][nxt.sc]>d+w){
dist[nxt.fs][nxt.sc] = d+w;
if(w==1)dq.push_back(make_pair(nxt,d+w));
else dq.push_front(make_pair(nxt,d+w));
}
}
}
cout<<dist[e.fs][e.sc]<<'\n';
return;
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>R>>C>>N;
cin>>s.fs>>s.sc>>e.fs>>e.sc;
arr = vector<string>(R);
for(int i = 0;i<R;i++)cin>>arr[i];
s.fs--,s.sc--,e.fs--,e.sc--;
if(N==1)N1::GO();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
5 ms |
1364 KB |
Output is correct |
33 |
Correct |
5 ms |
1268 KB |
Output is correct |
34 |
Correct |
2 ms |
2024 KB |
Output is correct |
35 |
Correct |
3 ms |
2024 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
5 ms |
1396 KB |
Output is correct |
38 |
Correct |
4 ms |
1372 KB |
Output is correct |
39 |
Correct |
38 ms |
9476 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
3 ms |
2292 KB |
Output is correct |
42 |
Correct |
7 ms |
1628 KB |
Output is correct |
43 |
Correct |
6 ms |
2396 KB |
Output is correct |
44 |
Correct |
20 ms |
5468 KB |
Output is correct |
45 |
Correct |
23 ms |
5716 KB |
Output is correct |
46 |
Correct |
37 ms |
18668 KB |
Output is correct |
47 |
Correct |
44 ms |
9316 KB |
Output is correct |
48 |
Correct |
37 ms |
9312 KB |
Output is correct |
49 |
Correct |
18 ms |
15104 KB |
Output is correct |
50 |
Correct |
31 ms |
15104 KB |
Output is correct |
51 |
Correct |
46 ms |
9820 KB |
Output is correct |
52 |
Correct |
55 ms |
9596 KB |
Output is correct |
53 |
Correct |
42 ms |
9504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
5 ms |
1364 KB |
Output is correct |
33 |
Correct |
5 ms |
1268 KB |
Output is correct |
34 |
Correct |
2 ms |
2024 KB |
Output is correct |
35 |
Correct |
3 ms |
2024 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
5 ms |
1396 KB |
Output is correct |
38 |
Correct |
4 ms |
1372 KB |
Output is correct |
39 |
Correct |
38 ms |
9476 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
3 ms |
2292 KB |
Output is correct |
42 |
Correct |
7 ms |
1628 KB |
Output is correct |
43 |
Correct |
6 ms |
2396 KB |
Output is correct |
44 |
Correct |
20 ms |
5468 KB |
Output is correct |
45 |
Correct |
23 ms |
5716 KB |
Output is correct |
46 |
Correct |
37 ms |
18668 KB |
Output is correct |
47 |
Correct |
44 ms |
9316 KB |
Output is correct |
48 |
Correct |
37 ms |
9312 KB |
Output is correct |
49 |
Correct |
18 ms |
15104 KB |
Output is correct |
50 |
Correct |
31 ms |
15104 KB |
Output is correct |
51 |
Correct |
46 ms |
9820 KB |
Output is correct |
52 |
Correct |
55 ms |
9596 KB |
Output is correct |
53 |
Correct |
42 ms |
9504 KB |
Output is correct |
54 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
5 ms |
1364 KB |
Output is correct |
33 |
Correct |
5 ms |
1268 KB |
Output is correct |
34 |
Correct |
2 ms |
2024 KB |
Output is correct |
35 |
Correct |
3 ms |
2024 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
5 ms |
1396 KB |
Output is correct |
38 |
Correct |
4 ms |
1372 KB |
Output is correct |
39 |
Correct |
38 ms |
9476 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
3 ms |
2292 KB |
Output is correct |
42 |
Correct |
7 ms |
1628 KB |
Output is correct |
43 |
Correct |
6 ms |
2396 KB |
Output is correct |
44 |
Correct |
20 ms |
5468 KB |
Output is correct |
45 |
Correct |
23 ms |
5716 KB |
Output is correct |
46 |
Correct |
37 ms |
18668 KB |
Output is correct |
47 |
Correct |
44 ms |
9316 KB |
Output is correct |
48 |
Correct |
37 ms |
9312 KB |
Output is correct |
49 |
Correct |
18 ms |
15104 KB |
Output is correct |
50 |
Correct |
31 ms |
15104 KB |
Output is correct |
51 |
Correct |
46 ms |
9820 KB |
Output is correct |
52 |
Correct |
55 ms |
9596 KB |
Output is correct |
53 |
Correct |
42 ms |
9504 KB |
Output is correct |
54 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
5 ms |
1364 KB |
Output is correct |
33 |
Correct |
5 ms |
1268 KB |
Output is correct |
34 |
Correct |
2 ms |
2024 KB |
Output is correct |
35 |
Correct |
3 ms |
2024 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
5 ms |
1396 KB |
Output is correct |
38 |
Correct |
4 ms |
1372 KB |
Output is correct |
39 |
Correct |
38 ms |
9476 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
3 ms |
2292 KB |
Output is correct |
42 |
Correct |
7 ms |
1628 KB |
Output is correct |
43 |
Correct |
6 ms |
2396 KB |
Output is correct |
44 |
Correct |
20 ms |
5468 KB |
Output is correct |
45 |
Correct |
23 ms |
5716 KB |
Output is correct |
46 |
Correct |
37 ms |
18668 KB |
Output is correct |
47 |
Correct |
44 ms |
9316 KB |
Output is correct |
48 |
Correct |
37 ms |
9312 KB |
Output is correct |
49 |
Correct |
18 ms |
15104 KB |
Output is correct |
50 |
Correct |
31 ms |
15104 KB |
Output is correct |
51 |
Correct |
46 ms |
9820 KB |
Output is correct |
52 |
Correct |
55 ms |
9596 KB |
Output is correct |
53 |
Correct |
42 ms |
9504 KB |
Output is correct |
54 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |