Submission #501337

# Submission time Handle Problem Language Result Execution time Memory
501337 2022-01-02T20:07:46 Z sidon Mecho (IOI09_mecho) C++17
84 / 100
281 ms 6168 KB
#include <bits/stdc++.h>
using namespace std;
#define c(X, Y) (X * N + Y)
 
const int INF = 1e8;
 
const int di[4] = {-1, 1, 0, 0};
const int dj[4] = {0, 0, -1, 1};
 
int N, S, h[1<<20], m[1<<20], o[1<<20], ans = -1, home;
 
string g[1<<10];
 
void BFS(char src, int *d, function<int(int, int, int)> valid) {
	fill(d, d + N * N, INF);
	queue<int> q;
	for(int i = 0; i < N; i++) 
		for(int j = 0; j < N; j++)
			if(g[i][j] == src)
				d[c(i, j)] = 0, q.push(c(i, j));
			else if(g[i][j] == 'D')
				home = c(i, j);
 
	while(!empty(q)) {
		int k = q.front(), i = k / N, j = k % N; q.pop();
 
		for(int s = 0; s < 4; s++) {
			int x = i + di[s], y = j + dj[s], z = c(x, y);
 
			if(min(x, y) < 0 || max(x, y) >= N || d[z] != INF) continue;
			if(valid(x, y, d[k] + 1))
				d[z] = d[k] + 1, q.push(z);
		}
	}
}
 
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> S;
 
	for(int i = 0; i < N; i++)
		cin >> g[i];
 
	BFS('H', h, [&](int i, int j, int k) {
		return g[i][j] & 1;
	});
 
	BFS('D', m, [&](int i, int j, int k) {
		return g[i][j] & 1;
	});
 
	for(int b = 30; --b >= 0; ) {
		ans += 1 << b;
		BFS('M', m, [&](int i, int j, int k) {
			return (g[i][j] & 1 || g[i][j] == 'D') && k / S + ans < h[c(i, j)];
		});
		if(m[home] == INF)
			ans -= 1 << b;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 109 ms 6092 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 372 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 10 ms 1452 KB Output is correct
34 Correct 10 ms 1356 KB Output is correct
35 Correct 26 ms 1456 KB Output is correct
36 Correct 12 ms 1792 KB Output is correct
37 Correct 12 ms 1740 KB Output is correct
38 Correct 38 ms 1740 KB Output is correct
39 Correct 16 ms 2172 KB Output is correct
40 Correct 16 ms 2168 KB Output is correct
41 Correct 54 ms 2168 KB Output is correct
42 Correct 19 ms 2592 KB Output is correct
43 Correct 22 ms 2592 KB Output is correct
44 Correct 53 ms 2508 KB Output is correct
45 Correct 26 ms 3020 KB Output is correct
46 Correct 23 ms 3052 KB Output is correct
47 Correct 71 ms 3008 KB Output is correct
48 Correct 45 ms 3532 KB Output is correct
49 Correct 28 ms 3532 KB Output is correct
50 Correct 93 ms 3564 KB Output is correct
51 Correct 31 ms 4124 KB Output is correct
52 Correct 33 ms 4044 KB Output is correct
53 Correct 95 ms 4116 KB Output is correct
54 Correct 44 ms 4696 KB Output is correct
55 Correct 52 ms 4696 KB Output is correct
56 Correct 122 ms 4696 KB Output is correct
57 Correct 44 ms 5332 KB Output is correct
58 Correct 46 ms 5332 KB Output is correct
59 Correct 128 ms 5348 KB Output is correct
60 Correct 47 ms 5964 KB Output is correct
61 Correct 48 ms 5964 KB Output is correct
62 Correct 192 ms 6024 KB Output is correct
63 Correct 158 ms 5952 KB Output is correct
64 Correct 224 ms 6028 KB Output is correct
65 Correct 281 ms 5952 KB Output is correct
66 Correct 176 ms 6028 KB Output is correct
67 Correct 169 ms 6024 KB Output is correct
68 Correct 101 ms 5972 KB Output is correct
69 Correct 92 ms 5968 KB Output is correct
70 Correct 80 ms 5964 KB Output is correct
71 Correct 77 ms 6048 KB Output is correct
72 Incorrect 72 ms 6040 KB Output isn't correct
73 Incorrect 76 ms 6112 KB Output isn't correct
74 Correct 118 ms 6164 KB Output is correct
75 Correct 96 ms 6096 KB Output is correct
76 Correct 91 ms 6168 KB Output is correct
77 Correct 105 ms 6160 KB Output is correct
78 Correct 110 ms 6072 KB Output is correct
79 Correct 82 ms 6092 KB Output is correct
80 Correct 92 ms 6156 KB Output is correct
81 Correct 99 ms 6156 KB Output is correct
82 Correct 99 ms 6160 KB Output is correct
83 Correct 112 ms 6128 KB Output is correct
84 Correct 95 ms 6136 KB Output is correct
85 Correct 96 ms 6132 KB Output is correct
86 Correct 107 ms 6136 KB Output is correct
87 Correct 107 ms 6092 KB Output is correct
88 Correct 106 ms 6048 KB Output is correct
89 Correct 108 ms 6112 KB Output is correct
90 Correct 112 ms 6092 KB Output is correct
91 Correct 120 ms 6040 KB Output is correct
92 Correct 109 ms 6112 KB Output is correct