Submission #607294

# Submission time Handle Problem Language Result Execution time Memory
607294 2022-07-26T14:36:40 Z beaboss Mecho (IOI09_mecho) C++14
26 / 100
93 ms 11148 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/s << endl;


	
	
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 0 ms 212 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 75 ms 11092 KB Output isn't correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is 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 0 ms 212 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Incorrect 1 ms 212 KB Output isn't correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Correct 0 ms 340 KB Output is correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Correct 0 ms 340 KB Output is correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Correct 1 ms 340 KB Output is correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Correct 1 ms 340 KB Output is correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Correct 1 ms 340 KB Output is correct
33 Incorrect 9 ms 2312 KB Output isn't correct
34 Correct 9 ms 2312 KB Output is correct
35 Incorrect 12 ms 2308 KB Output isn't correct
36 Incorrect 12 ms 2904 KB Output isn't correct
37 Correct 12 ms 3028 KB Output is correct
38 Incorrect 14 ms 3036 KB Output isn't correct
39 Incorrect 15 ms 3664 KB Output isn't correct
40 Correct 16 ms 3664 KB Output is correct
41 Incorrect 18 ms 3672 KB Output isn't correct
42 Incorrect 18 ms 4472 KB Output isn't correct
43 Correct 18 ms 4428 KB Output is correct
44 Incorrect 22 ms 4476 KB Output isn't correct
45 Incorrect 21 ms 5324 KB Output isn't correct
46 Correct 21 ms 5328 KB Output is correct
47 Incorrect 28 ms 5332 KB Output isn't correct
48 Incorrect 29 ms 6352 KB Output isn't correct
49 Correct 25 ms 6332 KB Output is correct
50 Incorrect 32 ms 6336 KB Output isn't correct
51 Incorrect 30 ms 7280 KB Output isn't correct
52 Correct 30 ms 7284 KB Output is correct
53 Incorrect 43 ms 7416 KB Output isn't correct
54 Incorrect 36 ms 8536 KB Output isn't correct
55 Correct 35 ms 8524 KB Output is correct
56 Incorrect 45 ms 8528 KB Output isn't correct
57 Incorrect 45 ms 9672 KB Output isn't correct
58 Correct 48 ms 9664 KB Output is correct
59 Incorrect 61 ms 9668 KB Output isn't correct
60 Incorrect 49 ms 11016 KB Output isn't correct
61 Correct 51 ms 11004 KB Output is correct
62 Incorrect 61 ms 11020 KB Output isn't correct
63 Correct 75 ms 11056 KB Output is correct
64 Correct 82 ms 11000 KB Output is correct
65 Correct 80 ms 11004 KB Output is correct
66 Incorrect 86 ms 11012 KB Output isn't correct
67 Correct 66 ms 11056 KB Output is correct
68 Correct 62 ms 11016 KB Output is correct
69 Correct 63 ms 10956 KB Output is correct
70 Correct 60 ms 11084 KB Output is correct
71 Correct 62 ms 11008 KB Output is correct
72 Incorrect 60 ms 11032 KB Output isn't correct
73 Incorrect 61 ms 11016 KB Output isn't correct
74 Correct 83 ms 11084 KB Output is correct
75 Correct 59 ms 11016 KB Output is correct
76 Correct 59 ms 11148 KB Output is correct
77 Correct 63 ms 11020 KB Output is correct
78 Correct 67 ms 11048 KB Output is correct
79 Incorrect 70 ms 11004 KB Output isn't correct
80 Incorrect 62 ms 11096 KB Output isn't correct
81 Incorrect 66 ms 11020 KB Output isn't correct
82 Incorrect 67 ms 11020 KB Output isn't correct
83 Correct 76 ms 11128 KB Output is correct
84 Incorrect 75 ms 11008 KB Output isn't correct
85 Incorrect 64 ms 11080 KB Output isn't correct
86 Incorrect 64 ms 11092 KB Output isn't correct
87 Incorrect 70 ms 11092 KB Output isn't correct
88 Correct 63 ms 11016 KB Output is correct
89 Incorrect 93 ms 11092 KB Output isn't correct
90 Incorrect 67 ms 11016 KB Output isn't correct
91 Incorrect 69 ms 11032 KB Output isn't correct
92 Incorrect 63 ms 11036 KB Output isn't correct