# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
607292 |
2022-07-26T14:36:11 Z |
beaboss |
Mecho (IOI09_mecho) |
C++14 |
|
100 ms |
11740 KB |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
cin >> n>> s;
vector<vector<char> > grid(n, vector<char>(n));
queue<pair<int ,int> > q1;
queue<pair<int ,int> > q2;
pair<int ,int> home;
pair<int ,int> start;
vector<vector<int> > hdist(n, vector<int>(n, -1));
vector<vector<int> > mdist(n, vector<int>(n, -1));
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'H') {
q1.push({i, j});
hdist[i][j] = 0;
}
else if (grid[i][j] == 'M') {
q2.push({i, j});
mdist[i][j] = 0;
start = {i, j};
}
else if (grid[i][j] == 'D') home = {i, j};
}
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
while (!q1.empty() && hdist[home.first][home.second] == -1) {
pair<int, int> curr = q1.front();
q1.pop();
for (int i = 0; i < 4; i++) {
int x = curr.first + dx[i];
int y = curr.second + dy[i];
if (x >= 0 && x < n && y >= 0 && y < n) {
if (hdist[x][y] == -1 && grid[x][y] == 'G') {
hdist[x][y] = hdist[curr.first][curr.second] + s;
q1.push({x, y});
}
}
}
}
vector<vector<pair<int, int> > > parent(n, vector<pair<int, int> >(n, {-1, -1}));
while (!q2.empty() && mdist[home.first][home.second] == -1) {
pair<int, int> curr = q2.front();
q2.pop();
for (int i = 0; i < 4; i++) {
int x = curr.first + dx[i];
int y = curr.second + dy[i];
if (x >= 0 && x < n && y >= 0 && y < n) {
if (mdist[x][y] == -1 && (grid[x][y] == 'G' || grid[x][y] == 'D') && (hdist[x][y] > mdist[curr.first][curr.second] + 1 || hdist[x][y ] == -1)) {
mdist[x][y] = mdist[curr.first][curr.second] + 1;
q2.push({x, y});
parent[x][y] = {curr.first, curr.second};
}
}
}
}
int ans = 100000000;
pair<int ,int> current = home;
// cout << mdist[home.first][home.second] << endl;
if (mdist[home.first][home.second] == -1) {
cout << -1 << endl;
return 0;
}
while (current != start) {
int x = current.first;
int y = current.second;
if (hdist[x][y] != -1) {
// cout << x << y << hdist[x][y] << endl;
ans = min(ans, hdist[x][y]-mdist[x][y]);
}
current = parent[x][y];
}
// for (int i = 0; i < 4; i++) {
// int x = home.first + dx[i];
// int y = home.second + dy[i];
// if (x >= 0 && x < n && y >= 0 && y < n && grid[x][y] != 'T') {
// ans = max(hdist[x][y] - mdist[x][y], ans);
// cout << mdist[x][y] << hdist[x][y] << x << y << endl;
// }
// }
cout << ans/3 << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
82 ms |
11640 KB |
Output isn't correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
292 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
33 |
Incorrect |
10 ms |
2484 KB |
Output isn't correct |
34 |
Incorrect |
9 ms |
2388 KB |
Output isn't correct |
35 |
Incorrect |
12 ms |
2388 KB |
Output isn't correct |
36 |
Incorrect |
12 ms |
3188 KB |
Output isn't correct |
37 |
Incorrect |
13 ms |
3156 KB |
Output isn't correct |
38 |
Incorrect |
15 ms |
3156 KB |
Output isn't correct |
39 |
Incorrect |
15 ms |
3924 KB |
Output isn't correct |
40 |
Incorrect |
17 ms |
3864 KB |
Output isn't correct |
41 |
Incorrect |
18 ms |
3864 KB |
Output isn't correct |
42 |
Incorrect |
19 ms |
4724 KB |
Output isn't correct |
43 |
Incorrect |
18 ms |
4796 KB |
Output isn't correct |
44 |
Incorrect |
22 ms |
4712 KB |
Output isn't correct |
45 |
Incorrect |
22 ms |
5588 KB |
Output isn't correct |
46 |
Incorrect |
22 ms |
5612 KB |
Output isn't correct |
47 |
Incorrect |
28 ms |
5580 KB |
Output isn't correct |
48 |
Incorrect |
27 ms |
6716 KB |
Output isn't correct |
49 |
Incorrect |
32 ms |
6688 KB |
Output isn't correct |
50 |
Incorrect |
36 ms |
6700 KB |
Output isn't correct |
51 |
Incorrect |
32 ms |
7904 KB |
Output isn't correct |
52 |
Incorrect |
31 ms |
7724 KB |
Output isn't correct |
53 |
Incorrect |
44 ms |
7832 KB |
Output isn't correct |
54 |
Incorrect |
37 ms |
9004 KB |
Output isn't correct |
55 |
Incorrect |
38 ms |
9012 KB |
Output isn't correct |
56 |
Incorrect |
52 ms |
9004 KB |
Output isn't correct |
57 |
Incorrect |
41 ms |
10224 KB |
Output isn't correct |
58 |
Incorrect |
44 ms |
10304 KB |
Output isn't correct |
59 |
Incorrect |
52 ms |
10212 KB |
Output isn't correct |
60 |
Incorrect |
45 ms |
11628 KB |
Output isn't correct |
61 |
Incorrect |
45 ms |
11632 KB |
Output isn't correct |
62 |
Incorrect |
59 ms |
11632 KB |
Output isn't correct |
63 |
Correct |
78 ms |
11632 KB |
Output is correct |
64 |
Incorrect |
81 ms |
11688 KB |
Output isn't correct |
65 |
Incorrect |
83 ms |
11644 KB |
Output isn't correct |
66 |
Incorrect |
76 ms |
11684 KB |
Output isn't correct |
67 |
Correct |
71 ms |
11628 KB |
Output is correct |
68 |
Incorrect |
64 ms |
11740 KB |
Output isn't correct |
69 |
Incorrect |
66 ms |
11624 KB |
Output isn't correct |
70 |
Incorrect |
62 ms |
11704 KB |
Output isn't correct |
71 |
Incorrect |
62 ms |
11636 KB |
Output isn't correct |
72 |
Incorrect |
79 ms |
11624 KB |
Output isn't correct |
73 |
Incorrect |
67 ms |
11636 KB |
Output isn't correct |
74 |
Incorrect |
84 ms |
11632 KB |
Output isn't correct |
75 |
Incorrect |
61 ms |
11724 KB |
Output isn't correct |
76 |
Incorrect |
67 ms |
11644 KB |
Output isn't correct |
77 |
Incorrect |
67 ms |
11736 KB |
Output isn't correct |
78 |
Correct |
85 ms |
11644 KB |
Output is correct |
79 |
Incorrect |
87 ms |
11628 KB |
Output isn't correct |
80 |
Incorrect |
72 ms |
11644 KB |
Output isn't correct |
81 |
Incorrect |
69 ms |
11648 KB |
Output isn't correct |
82 |
Incorrect |
66 ms |
11640 KB |
Output isn't correct |
83 |
Incorrect |
65 ms |
11648 KB |
Output isn't correct |
84 |
Incorrect |
100 ms |
11628 KB |
Output isn't correct |
85 |
Incorrect |
68 ms |
11732 KB |
Output isn't correct |
86 |
Incorrect |
63 ms |
11716 KB |
Output isn't correct |
87 |
Incorrect |
70 ms |
11624 KB |
Output isn't correct |
88 |
Correct |
73 ms |
11644 KB |
Output is correct |
89 |
Incorrect |
93 ms |
11596 KB |
Output isn't correct |
90 |
Incorrect |
74 ms |
11632 KB |
Output isn't correct |
91 |
Incorrect |
74 ms |
11636 KB |
Output isn't correct |
92 |
Incorrect |
70 ms |
11628 KB |
Output isn't correct |