// subtask 1
// ca n-am idei
// cred ca o astfel de pb s-ar putea da la lot
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
int n, m, k, si, sj, ei, ej;
cin >> n >> m >> k >> si >> sj >> ei >> ej;
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
vector<vector<char>> mat(n + 1, vector<char>(m + 1));
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cin >> mat[i][j];
dp[i][j] = 1e9;
}
}
deque<pair<int, int>> dq;
dq.push_back({si, sj});
dp[si][sj] = 0;
if(mat[si][sj] == '#') {
dp[si][sj] ++;
}
while(!dq.empty()) {
int i = dq.front().first, j = dq.front().second;
dq.pop_front();
for(int d = 0; d < 4; d ++) {
int x = i + dx[d];
int y = j + dy[d];
if(x < 1 || y < 1 || x > n || y > m) {
continue;
}
if(dp[x][y] > dp[i][j] + (mat[x][y] == '#')) {
dp[x][y] = dp[i][j] + (mat[x][y] == '#');
if(dq.empty() || dp[dq.front().first][dq.front().second] > dp[x][y]) {
dq.push_front({x, y});
} else {
dq.push_back({x, y});
}
}
}
}
cout << dp[ei][ej];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
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 |
0 ms |
348 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 |
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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
704 KB |
Output is correct |
20 |
Correct |
3 ms |
1184 KB |
Output is correct |
21 |
Correct |
4 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
804 KB |
Output is correct |
23 |
Correct |
4 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
1136 KB |
Output is correct |
25 |
Correct |
3 ms |
1136 KB |
Output is correct |
26 |
Correct |
7 ms |
828 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
1116 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
8 ms |
1372 KB |
Output is correct |
32 |
Correct |
17 ms |
1372 KB |
Output is correct |
33 |
Correct |
9 ms |
1112 KB |
Output is correct |
34 |
Correct |
8 ms |
2136 KB |
Output is correct |
35 |
Correct |
8 ms |
2208 KB |
Output is correct |
36 |
Correct |
27 ms |
1372 KB |
Output is correct |
37 |
Correct |
21 ms |
1552 KB |
Output is correct |
38 |
Correct |
8 ms |
1116 KB |
Output is correct |
39 |
Correct |
105 ms |
9324 KB |
Output is correct |
40 |
Correct |
44 ms |
1372 KB |
Output is correct |
41 |
Correct |
9 ms |
2948 KB |
Output is correct |
42 |
Correct |
19 ms |
1624 KB |
Output is correct |
43 |
Correct |
15 ms |
2428 KB |
Output is correct |
44 |
Correct |
57 ms |
5496 KB |
Output is correct |
45 |
Correct |
52 ms |
5852 KB |
Output is correct |
46 |
Correct |
77 ms |
11164 KB |
Output is correct |
47 |
Correct |
287 ms |
9296 KB |
Output is correct |
48 |
Correct |
114 ms |
9340 KB |
Output is correct |
49 |
Correct |
69 ms |
18012 KB |
Output is correct |
50 |
Correct |
69 ms |
18012 KB |
Output is correct |
51 |
Correct |
597 ms |
9552 KB |
Output is correct |
52 |
Correct |
330 ms |
9556 KB |
Output is correct |
53 |
Correct |
88 ms |
9360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
344 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 |
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 |
0 ms |
348 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 |
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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
704 KB |
Output is correct |
20 |
Correct |
3 ms |
1184 KB |
Output is correct |
21 |
Correct |
4 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
804 KB |
Output is correct |
23 |
Correct |
4 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
1136 KB |
Output is correct |
25 |
Correct |
3 ms |
1136 KB |
Output is correct |
26 |
Correct |
7 ms |
828 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
1116 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
8 ms |
1372 KB |
Output is correct |
32 |
Correct |
17 ms |
1372 KB |
Output is correct |
33 |
Correct |
9 ms |
1112 KB |
Output is correct |
34 |
Correct |
8 ms |
2136 KB |
Output is correct |
35 |
Correct |
8 ms |
2208 KB |
Output is correct |
36 |
Correct |
27 ms |
1372 KB |
Output is correct |
37 |
Correct |
21 ms |
1552 KB |
Output is correct |
38 |
Correct |
8 ms |
1116 KB |
Output is correct |
39 |
Correct |
105 ms |
9324 KB |
Output is correct |
40 |
Correct |
44 ms |
1372 KB |
Output is correct |
41 |
Correct |
9 ms |
2948 KB |
Output is correct |
42 |
Correct |
19 ms |
1624 KB |
Output is correct |
43 |
Correct |
15 ms |
2428 KB |
Output is correct |
44 |
Correct |
57 ms |
5496 KB |
Output is correct |
45 |
Correct |
52 ms |
5852 KB |
Output is correct |
46 |
Correct |
77 ms |
11164 KB |
Output is correct |
47 |
Correct |
287 ms |
9296 KB |
Output is correct |
48 |
Correct |
114 ms |
9340 KB |
Output is correct |
49 |
Correct |
69 ms |
18012 KB |
Output is correct |
50 |
Correct |
69 ms |
18012 KB |
Output is correct |
51 |
Correct |
597 ms |
9552 KB |
Output is correct |
52 |
Correct |
330 ms |
9556 KB |
Output is correct |
53 |
Correct |
88 ms |
9360 KB |
Output is correct |
54 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
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 |
0 ms |
348 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 |
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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
704 KB |
Output is correct |
20 |
Correct |
3 ms |
1184 KB |
Output is correct |
21 |
Correct |
4 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
804 KB |
Output is correct |
23 |
Correct |
4 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
1136 KB |
Output is correct |
25 |
Correct |
3 ms |
1136 KB |
Output is correct |
26 |
Correct |
7 ms |
828 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
1116 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
8 ms |
1372 KB |
Output is correct |
32 |
Correct |
17 ms |
1372 KB |
Output is correct |
33 |
Correct |
9 ms |
1112 KB |
Output is correct |
34 |
Correct |
8 ms |
2136 KB |
Output is correct |
35 |
Correct |
8 ms |
2208 KB |
Output is correct |
36 |
Correct |
27 ms |
1372 KB |
Output is correct |
37 |
Correct |
21 ms |
1552 KB |
Output is correct |
38 |
Correct |
8 ms |
1116 KB |
Output is correct |
39 |
Correct |
105 ms |
9324 KB |
Output is correct |
40 |
Correct |
44 ms |
1372 KB |
Output is correct |
41 |
Correct |
9 ms |
2948 KB |
Output is correct |
42 |
Correct |
19 ms |
1624 KB |
Output is correct |
43 |
Correct |
15 ms |
2428 KB |
Output is correct |
44 |
Correct |
57 ms |
5496 KB |
Output is correct |
45 |
Correct |
52 ms |
5852 KB |
Output is correct |
46 |
Correct |
77 ms |
11164 KB |
Output is correct |
47 |
Correct |
287 ms |
9296 KB |
Output is correct |
48 |
Correct |
114 ms |
9340 KB |
Output is correct |
49 |
Correct |
69 ms |
18012 KB |
Output is correct |
50 |
Correct |
69 ms |
18012 KB |
Output is correct |
51 |
Correct |
597 ms |
9552 KB |
Output is correct |
52 |
Correct |
330 ms |
9556 KB |
Output is correct |
53 |
Correct |
88 ms |
9360 KB |
Output is correct |
54 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
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 |
0 ms |
348 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 |
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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
704 KB |
Output is correct |
20 |
Correct |
3 ms |
1184 KB |
Output is correct |
21 |
Correct |
4 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
804 KB |
Output is correct |
23 |
Correct |
4 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
1136 KB |
Output is correct |
25 |
Correct |
3 ms |
1136 KB |
Output is correct |
26 |
Correct |
7 ms |
828 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
1116 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
8 ms |
1372 KB |
Output is correct |
32 |
Correct |
17 ms |
1372 KB |
Output is correct |
33 |
Correct |
9 ms |
1112 KB |
Output is correct |
34 |
Correct |
8 ms |
2136 KB |
Output is correct |
35 |
Correct |
8 ms |
2208 KB |
Output is correct |
36 |
Correct |
27 ms |
1372 KB |
Output is correct |
37 |
Correct |
21 ms |
1552 KB |
Output is correct |
38 |
Correct |
8 ms |
1116 KB |
Output is correct |
39 |
Correct |
105 ms |
9324 KB |
Output is correct |
40 |
Correct |
44 ms |
1372 KB |
Output is correct |
41 |
Correct |
9 ms |
2948 KB |
Output is correct |
42 |
Correct |
19 ms |
1624 KB |
Output is correct |
43 |
Correct |
15 ms |
2428 KB |
Output is correct |
44 |
Correct |
57 ms |
5496 KB |
Output is correct |
45 |
Correct |
52 ms |
5852 KB |
Output is correct |
46 |
Correct |
77 ms |
11164 KB |
Output is correct |
47 |
Correct |
287 ms |
9296 KB |
Output is correct |
48 |
Correct |
114 ms |
9340 KB |
Output is correct |
49 |
Correct |
69 ms |
18012 KB |
Output is correct |
50 |
Correct |
69 ms |
18012 KB |
Output is correct |
51 |
Correct |
597 ms |
9552 KB |
Output is correct |
52 |
Correct |
330 ms |
9556 KB |
Output is correct |
53 |
Correct |
88 ms |
9360 KB |
Output is correct |
54 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |