Submission #575911

# Submission time Handle Problem Language Result Execution time Memory
575911 2022-06-11T16:19:37 Z acatmeowmeow Mecho (IOI09_mecho) C++11
15 / 100
1000 ms 13192 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 = n*n, 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 0 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Execution timed out 1081 ms 12664 KB Time limit exceeded
8 Incorrect 1 ms 468 KB Output isn't correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Incorrect 5 ms 980 KB Output isn't correct
13 Incorrect 4 ms 852 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 468 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 852 KB Output isn't correct
22 Correct 2 ms 724 KB Output is correct
23 Incorrect 5 ms 852 KB Output isn't correct
24 Correct 4 ms 852 KB Output is correct
25 Incorrect 5 ms 980 KB Output isn't correct
26 Correct 5 ms 980 KB Output is correct
27 Incorrect 6 ms 980 KB Output isn't correct
28 Correct 6 ms 1092 KB Output is correct
29 Incorrect 7 ms 1108 KB Output isn't correct
30 Correct 9 ms 1108 KB Output is correct
31 Incorrect 8 ms 1108 KB Output isn't correct
32 Correct 10 ms 1212 KB Output is correct
33 Incorrect 191 ms 5460 KB Output isn't correct
34 Correct 195 ms 5580 KB Output is correct
35 Correct 225 ms 5588 KB Output is correct
36 Incorrect 270 ms 6228 KB Output isn't correct
37 Correct 267 ms 6324 KB Output is correct
38 Correct 308 ms 6320 KB Output is correct
39 Incorrect 346 ms 7060 KB Output isn't correct
40 Correct 341 ms 7056 KB Output is correct
41 Correct 382 ms 6996 KB Output is correct
42 Incorrect 420 ms 7764 KB Output isn't correct
43 Correct 415 ms 7804 KB Output is correct
44 Correct 480 ms 7764 KB Output is correct
45 Incorrect 555 ms 8556 KB Output isn't correct
46 Correct 507 ms 8556 KB Output is correct
47 Correct 573 ms 8564 KB Output is correct
48 Incorrect 640 ms 9324 KB Output isn't correct
49 Correct 632 ms 9420 KB Output is correct
50 Correct 695 ms 9300 KB Output is correct
51 Incorrect 740 ms 10068 KB Output isn't correct
52 Correct 742 ms 10052 KB Output is correct
53 Correct 907 ms 10080 KB Output is correct
54 Incorrect 845 ms 10796 KB Output isn't correct
55 Correct 862 ms 10796 KB Output is correct
56 Execution timed out 1036 ms 10816 KB Time limit exceeded
57 Execution timed out 1006 ms 11560 KB Time limit exceeded
58 Correct 982 ms 11604 KB Output is correct
59 Execution timed out 1088 ms 11476 KB Time limit exceeded
60 Execution timed out 1083 ms 12244 KB Time limit exceeded
61 Execution timed out 1077 ms 12244 KB Time limit exceeded
62 Execution timed out 1090 ms 12244 KB Time limit exceeded
63 Execution timed out 1089 ms 12272 KB Time limit exceeded
64 Execution timed out 1094 ms 12244 KB Time limit exceeded
65 Execution timed out 1094 ms 12328 KB Time limit exceeded
66 Execution timed out 1100 ms 12244 KB Time limit exceeded
67 Execution timed out 1092 ms 12244 KB Time limit exceeded
68 Execution timed out 1088 ms 12372 KB Time limit exceeded
69 Execution timed out 1087 ms 12380 KB Time limit exceeded
70 Execution timed out 1095 ms 12372 KB Time limit exceeded
71 Execution timed out 1091 ms 12300 KB Time limit exceeded
72 Execution timed out 1059 ms 12372 KB Time limit exceeded
73 Execution timed out 1095 ms 13192 KB Time limit exceeded
74 Execution timed out 1095 ms 12976 KB Time limit exceeded
75 Execution timed out 1082 ms 13000 KB Time limit exceeded
76 Execution timed out 1098 ms 12988 KB Time limit exceeded
77 Execution timed out 1085 ms 13084 KB Time limit exceeded
78 Execution timed out 1097 ms 13004 KB Time limit exceeded
79 Execution timed out 1096 ms 13116 KB Time limit exceeded
80 Execution timed out 1093 ms 12980 KB Time limit exceeded
81 Execution timed out 1098 ms 13004 KB Time limit exceeded
82 Execution timed out 1093 ms 13008 KB Time limit exceeded
83 Execution timed out 1096 ms 12704 KB Time limit exceeded
84 Execution timed out 1100 ms 12740 KB Time limit exceeded
85 Execution timed out 1086 ms 12780 KB Time limit exceeded
86 Execution timed out 1099 ms 12792 KB Time limit exceeded
87 Execution timed out 1089 ms 12896 KB Time limit exceeded
88 Execution timed out 1093 ms 12684 KB Time limit exceeded
89 Execution timed out 1070 ms 12680 KB Time limit exceeded
90 Execution timed out 1094 ms 12748 KB Time limit exceeded
91 Execution timed out 1098 ms 12688 KB Time limit exceeded
92 Execution timed out 1099 ms 12720 KB Time limit exceeded