Submission #575910

# Submission time Handle Problem Language Result Execution time Memory
575910 2022-06-11T16:16:22 Z acatmeowmeow Mecho (IOI09_mecho) C++11
27 / 100
878 ms 13768 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long 

const int N = 8e2 + 5;
int n, s;
char grid[N][N];
pair<int, int> init, home;
vector<pair<int, int>> hive;

vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
int dmecho[N][N], dbee[N][N];
bool vmecho[N][N], vbee[N][N];
queue<pair<int, int>> qmecho, qbee;

bool bee_inbound(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= n && !vbee[x][y] && grid[x][y] == 'G';
}

bool mecho_inbound(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= n && !vmecho[x][y] && (grid[x][y] == 'G' || grid[x][y] == 'D');
}

bool valid(int m) {
	// initialize
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dmecho[i][j] = dbee[i][j] = 1e18;
			vmecho[i][j] = vbee[i][j] = false;
		}
	}
	// mecho eats and bee move
	for (auto&u : hive) {
		int x = u.first, y = u.second;
		dbee[x][y] = 0, qbee.push({x, y});
	}
	for (int i = 1; i <= n*n; i++) {
		queue<pair<int, int>> nex;
		while (qbee.size()) {
			int x = qbee.front().first, y = qbee.front().second; qbee.pop();
			for (int k = 0; k < 4; k++) {
				int tox = x + dx[k], toy = y + dy[k];
				if (!bee_inbound(tox, toy)) continue;
				if (dbee[tox][toy] <= max(1ll, i - m + 1)) continue;
				dbee[tox][toy] = max(1ll, i - m + 1), vbee[tox][toy] = true, nex.push({tox, toy});
			}
		}
		swap(nex, qbee);
	}
	// debug
	/*for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << (dbee[i][j] == 1e18 ? -1 : dbee[i][j]) << ' ';
		}
		cout << '\n';
	}*/
	// debug
	int x = init.first, y = init.second;
	dmecho[x][y] = 0, vmecho[x][y] = true, qmecho.push({x, y});
	for (int i = 1; i <= (n*n + s - 1)/s; i++) {
		for (int j = 1; j <= s; j++) {
			queue<pair<int, int>> nex;
			while (qmecho.size()) {
				int x = qmecho.front().first, y = qmecho.front().second; qmecho.pop();
				if (dmecho[x][y] >= dbee[x][y]) continue;
				for (int k = 0; k < 4; k++) {
					int tox = x + dx[k], toy = y + dy[k];
					if (!mecho_inbound(tox, toy)) continue;
					if (dmecho[tox][toy] <= i) continue;
					dmecho[tox][toy] = i, vmecho[tox][toy] = true, nex.push({tox, toy});
				}
			}
			swap(nex, qmecho);
		}
	}
	x = home.first, y = home.second;
	return dmecho[x][y] < dbee[x][y];
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> s;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> grid[i][j];
			if (grid[i][j] == 'M') init = {i, j};
			else if (grid[i][j] == 'D') home = {i, j};
			else if(grid[i][j] == 'H') hive.push_back({i, j});
		}
	}
	int l = 0, r = 1000, ans = 0;
	while (l <= r) {
		int m = (l + r)/2;
		if (valid(m)) ans = m, l = m + 1;
		else r = m - 1;
	}
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 795 ms 13184 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Incorrect 4 ms 980 KB Output isn't correct
13 Incorrect 4 ms 844 KB Output isn't correct
14 Incorrect 5 ms 980 KB Output isn't correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Correct 1 ms 464 KB Output is correct
17 Incorrect 1 ms 596 KB Output isn't correct
18 Correct 1 ms 596 KB Output is correct
19 Incorrect 1 ms 596 KB Output isn't correct
20 Correct 2 ms 596 KB Output is correct
21 Incorrect 2 ms 724 KB Output isn't correct
22 Correct 3 ms 724 KB Output is correct
23 Incorrect 4 ms 852 KB Output isn't correct
24 Correct 3 ms 848 KB Output is correct
25 Incorrect 4 ms 980 KB Output isn't correct
26 Correct 4 ms 980 KB Output is correct
27 Incorrect 5 ms 980 KB Output isn't correct
28 Correct 5 ms 980 KB Output is correct
29 Incorrect 9 ms 1164 KB Output isn't correct
30 Incorrect 6 ms 1108 KB Output isn't correct
31 Incorrect 6 ms 1108 KB Output isn't correct
32 Incorrect 6 ms 1104 KB Output isn't correct
33 Incorrect 129 ms 5588 KB Output isn't correct
34 Incorrect 133 ms 5708 KB Output isn't correct
35 Correct 140 ms 5688 KB Output is correct
36 Incorrect 165 ms 6468 KB Output isn't correct
37 Incorrect 178 ms 6484 KB Output isn't correct
38 Correct 190 ms 6604 KB Output is correct
39 Incorrect 211 ms 7252 KB Output isn't correct
40 Incorrect 222 ms 7264 KB Output isn't correct
41 Correct 236 ms 7264 KB Output is correct
42 Incorrect 255 ms 8056 KB Output isn't correct
43 Incorrect 277 ms 8056 KB Output isn't correct
44 Correct 292 ms 8020 KB Output is correct
45 Incorrect 310 ms 8788 KB Output isn't correct
46 Incorrect 327 ms 8852 KB Output isn't correct
47 Correct 373 ms 8864 KB Output is correct
48 Incorrect 370 ms 9684 KB Output isn't correct
49 Incorrect 383 ms 9560 KB Output isn't correct
50 Correct 438 ms 9684 KB Output is correct
51 Incorrect 439 ms 10476 KB Output isn't correct
52 Incorrect 461 ms 10476 KB Output isn't correct
53 Correct 516 ms 10572 KB Output is correct
54 Incorrect 513 ms 11284 KB Output isn't correct
55 Incorrect 523 ms 11280 KB Output isn't correct
56 Correct 611 ms 11308 KB Output is correct
57 Incorrect 579 ms 12136 KB Output isn't correct
58 Incorrect 602 ms 11988 KB Output isn't correct
59 Correct 707 ms 12120 KB Output is correct
60 Incorrect 655 ms 12936 KB Output isn't correct
61 Incorrect 687 ms 12876 KB Output isn't correct
62 Correct 783 ms 13048 KB Output is correct
63 Correct 878 ms 12944 KB Output is correct
64 Correct 870 ms 12940 KB Output is correct
65 Correct 876 ms 12948 KB Output is correct
66 Incorrect 871 ms 12944 KB Output isn't correct
67 Incorrect 803 ms 13004 KB Output isn't correct
68 Correct 755 ms 13012 KB Output is correct
69 Correct 750 ms 13012 KB Output is correct
70 Correct 761 ms 13140 KB Output is correct
71 Correct 745 ms 13112 KB Output is correct
72 Incorrect 737 ms 13012 KB Output isn't correct
73 Incorrect 785 ms 13612 KB Output isn't correct
74 Correct 742 ms 13596 KB Output is correct
75 Correct 784 ms 13664 KB Output is correct
76 Correct 760 ms 13596 KB Output is correct
77 Correct 703 ms 13636 KB Output is correct
78 Incorrect 724 ms 13644 KB Output isn't correct
79 Correct 750 ms 13640 KB Output is correct
80 Correct 749 ms 13644 KB Output is correct
81 Correct 761 ms 13516 KB Output is correct
82 Correct 791 ms 13768 KB Output is correct
83 Correct 789 ms 13416 KB Output is correct
84 Correct 807 ms 13604 KB Output is correct
85 Correct 775 ms 13520 KB Output is correct
86 Correct 812 ms 13460 KB Output is correct
87 Correct 783 ms 13552 KB Output is correct
88 Correct 804 ms 13340 KB Output is correct
89 Correct 789 ms 13388 KB Output is correct
90 Correct 795 ms 13268 KB Output is correct
91 Correct 786 ms 13436 KB Output is correct
92 Correct 820 ms 13388 KB Output is correct