Submission #501150

# Submission time Handle Problem Language Result Execution time Memory
501150 2022-01-02T13:29:27 Z sidon Mecho (IOI09_mecho) C++17
38 / 100
211 ms 6684 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], ans = -1, home;

string g[1<<10];

void BFS(char src, int *d, function<bool(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;
	});

	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 - 1) / S + ans <= h[c(i, j)];
		});
		if(m[home] == INF)
			ans -= 1 << b;
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 103 ms 6580 KB Output is correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 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 Incorrect 0 ms 352 KB Output isn't correct
16 Correct 0 ms 332 KB Output is correct
17 Incorrect 0 ms 332 KB Output isn't correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Correct 1 ms 356 KB Output is correct
23 Incorrect 1 ms 352 KB Output isn't correct
24 Correct 1 ms 332 KB Output is correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Correct 1 ms 332 KB Output is correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Correct 1 ms 332 KB Output is correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Correct 1 ms 356 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Correct 1 ms 332 KB Output is correct
33 Incorrect 8 ms 1484 KB Output isn't correct
34 Correct 8 ms 1520 KB Output is correct
35 Correct 23 ms 1484 KB Output is correct
36 Incorrect 8 ms 1920 KB Output isn't correct
37 Correct 10 ms 1892 KB Output is correct
38 Correct 32 ms 1924 KB Output is correct
39 Incorrect 13 ms 2272 KB Output isn't correct
40 Correct 13 ms 2252 KB Output is correct
41 Correct 41 ms 2252 KB Output is correct
42 Incorrect 14 ms 2764 KB Output isn't correct
43 Correct 15 ms 2760 KB Output is correct
44 Correct 47 ms 2748 KB Output is correct
45 Incorrect 17 ms 3276 KB Output isn't correct
46 Correct 21 ms 3328 KB Output is correct
47 Correct 87 ms 3336 KB Output is correct
48 Incorrect 20 ms 3788 KB Output isn't correct
49 Correct 20 ms 3784 KB Output is correct
50 Correct 73 ms 3892 KB Output is correct
51 Incorrect 23 ms 4428 KB Output isn't correct
52 Correct 25 ms 4400 KB Output is correct
53 Correct 93 ms 4500 KB Output is correct
54 Incorrect 40 ms 5068 KB Output isn't correct
55 Correct 29 ms 5068 KB Output is correct
56 Correct 104 ms 5068 KB Output is correct
57 Incorrect 29 ms 5836 KB Output isn't correct
58 Correct 30 ms 5820 KB Output is correct
59 Correct 144 ms 5844 KB Output is correct
60 Incorrect 51 ms 6528 KB Output isn't correct
61 Correct 34 ms 6468 KB Output is correct
62 Correct 151 ms 6520 KB Output is correct
63 Correct 131 ms 6528 KB Output is correct
64 Correct 211 ms 6472 KB Output is correct
65 Correct 206 ms 6520 KB Output is correct
66 Incorrect 168 ms 6496 KB Output isn't correct
67 Correct 200 ms 6520 KB Output is correct
68 Correct 65 ms 6480 KB Output is correct
69 Correct 84 ms 6592 KB Output is correct
70 Correct 57 ms 6476 KB Output is correct
71 Correct 49 ms 6536 KB Output is correct
72 Incorrect 47 ms 6536 KB Output isn't correct
73 Incorrect 50 ms 6624 KB Output isn't correct
74 Correct 75 ms 6668 KB Output is correct
75 Correct 84 ms 6656 KB Output is correct
76 Correct 70 ms 6660 KB Output is correct
77 Correct 81 ms 6656 KB Output is correct
78 Correct 99 ms 6652 KB Output is correct
79 Correct 73 ms 6648 KB Output is correct
80 Correct 81 ms 6644 KB Output is correct
81 Correct 85 ms 6604 KB Output is correct
82 Correct 76 ms 6584 KB Output is correct
83 Correct 87 ms 6576 KB Output is correct
84 Correct 86 ms 6568 KB Output is correct
85 Correct 77 ms 6596 KB Output is correct
86 Correct 97 ms 6684 KB Output is correct
87 Correct 88 ms 6632 KB Output is correct
88 Correct 119 ms 6604 KB Output is correct
89 Correct 92 ms 6612 KB Output is correct
90 Correct 94 ms 6600 KB Output is correct
91 Correct 130 ms 6612 KB Output is correct
92 Correct 92 ms 6604 KB Output is correct