Submission #607297

# Submission time Handle Problem Language Result Execution time Memory
607297 2022-07-26T14:37:31 Z beaboss Mecho (IOI09_mecho) C++14
26 / 100
86 ms 21172 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
	ll n, s;

	cin >> n>> s;

	vector<vector<char> > grid(n, vector<char>(n));
	queue<pair<ll ,ll> > q1;
	queue<pair<ll ,ll> > q2;
	pair<ll ,ll> home;
	pair<ll ,ll> start;


	vector<vector<ll> > hdist(n, vector<ll>(n, -1));
	vector<vector<ll> > mdist(n, vector<ll>(n, -1));

	for (ll i = 0; i < n; i++) for (ll 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<ll> dx = {1, -1, 0, 0};
	vector<ll> dy = {0, 0, -1, 1};
	while (!q1.empty() && hdist[home.first][home.second] == -1) {
		pair<ll, ll> curr = q1.front();
		q1.pop();

		for (ll i = 0; i < 4; i++) {
			ll x = curr.first + dx[i];
			ll 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<ll, ll> > > parent(n, vector<pair<ll, ll> >(n, {-1, -1}));

	while (!q2.empty() && mdist[home.first][home.second] == -1) {
		pair<ll, ll> curr = q2.front();
		q2.pop();

		for (ll i = 0; i < 4; i++) {
			ll x = curr.first + dx[i];
			ll 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};
				}
			}
		}

	}
	ll ans = 100000000;
	pair<ll ,ll> current = home;
	// cout << mdist[home.first][home.second] << endl;
	if (mdist[home.first][home.second] == -1) {
		cout << -1 << endl;
		return 0;
	}

	while (current != start) {
		ll x = current.first;
		ll 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 (ll i = 0; i < 4; i++) {
	// 	ll x = home.first + dx[i];
	// 	ll 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 1 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 21140 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 0 ms 212 KB Output is correct
17 Incorrect 0 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 340 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 1 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 468 KB Output isn't correct
30 Correct 1 ms 468 KB Output is correct
31 Incorrect 1 ms 468 KB Output isn't correct
32 Correct 1 ms 468 KB Output is correct
33 Incorrect 10 ms 4296 KB Output isn't correct
34 Correct 11 ms 4300 KB Output is correct
35 Incorrect 13 ms 4296 KB Output isn't correct
36 Incorrect 13 ms 5440 KB Output isn't correct
37 Correct 12 ms 5532 KB Output is correct
38 Incorrect 16 ms 5444 KB Output isn't correct
39 Incorrect 16 ms 6868 KB Output isn't correct
40 Correct 16 ms 6788 KB Output is correct
41 Incorrect 19 ms 6868 KB Output isn't correct
42 Incorrect 19 ms 8360 KB Output isn't correct
43 Correct 19 ms 8356 KB Output is correct
44 Incorrect 24 ms 8456 KB Output isn't correct
45 Incorrect 24 ms 10132 KB Output isn't correct
46 Correct 23 ms 10128 KB Output is correct
47 Incorrect 28 ms 10144 KB Output isn't correct
48 Incorrect 27 ms 11988 KB Output isn't correct
49 Correct 27 ms 11972 KB Output is correct
50 Incorrect 35 ms 11988 KB Output isn't correct
51 Incorrect 32 ms 13928 KB Output isn't correct
52 Correct 32 ms 13984 KB Output is correct
53 Incorrect 43 ms 13940 KB Output isn't correct
54 Incorrect 41 ms 16216 KB Output isn't correct
55 Correct 38 ms 16200 KB Output is correct
56 Incorrect 56 ms 16228 KB Output isn't correct
57 Incorrect 42 ms 18508 KB Output isn't correct
58 Correct 42 ms 18580 KB Output is correct
59 Incorrect 56 ms 18580 KB Output isn't correct
60 Incorrect 50 ms 21024 KB Output isn't correct
61 Correct 48 ms 21020 KB Output is correct
62 Incorrect 65 ms 21020 KB Output isn't correct
63 Correct 77 ms 21008 KB Output is correct
64 Correct 82 ms 21020 KB Output is correct
65 Correct 78 ms 21088 KB Output is correct
66 Incorrect 77 ms 21008 KB Output isn't correct
67 Correct 71 ms 21024 KB Output is correct
68 Correct 66 ms 21064 KB Output is correct
69 Correct 70 ms 21016 KB Output is correct
70 Correct 66 ms 21060 KB Output is correct
71 Correct 75 ms 21068 KB Output is correct
72 Incorrect 63 ms 21068 KB Output isn't correct
73 Incorrect 68 ms 21048 KB Output isn't correct
74 Correct 86 ms 21160 KB Output is correct
75 Correct 67 ms 21172 KB Output is correct
76 Correct 64 ms 21148 KB Output is correct
77 Correct 67 ms 21048 KB Output is correct
78 Correct 66 ms 21036 KB Output is correct
79 Incorrect 79 ms 21144 KB Output isn't correct
80 Incorrect 67 ms 21160 KB Output isn't correct
81 Incorrect 66 ms 21156 KB Output isn't correct
82 Incorrect 69 ms 21152 KB Output isn't correct
83 Correct 75 ms 21148 KB Output is correct
84 Incorrect 84 ms 21044 KB Output isn't correct
85 Incorrect 73 ms 21144 KB Output isn't correct
86 Incorrect 68 ms 21068 KB Output isn't correct
87 Incorrect 71 ms 21148 KB Output isn't correct
88 Correct 68 ms 21152 KB Output is correct
89 Incorrect 82 ms 21040 KB Output isn't correct
90 Incorrect 86 ms 21156 KB Output isn't correct
91 Incorrect 80 ms 21148 KB Output isn't correct
92 Incorrect 69 ms 21140 KB Output isn't correct