Submission #501344

# Submission time Handle Problem Language Result Execution time Memory
501344 2022-01-02T20:41:47 Z sidon Mecho (IOI09_mecho) C++17
100 / 100
176 ms 6084 KB
#include <bits/stdc++.h>
using namespace std;
 
const int Z = 1<<20;
const int dx[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
 
int N, S, h[Z], m[Z], ans = -1, e, r;
string g, _;
 
void BFS(char src, int *d) {
	fill(d, d + N * N, Z);
	queue<int> q;
	for(int i = N * N; --i >= 0; ) {
		if(g[i] == src && ans < h[i])
			d[i] = 0, q.push(i);
		if(g[i] == 'D') e = i, g[i] = 30;
	}
 
	while(!empty(q)) {
		int k = q.front(), i = k / N, j = k % N; q.pop();

		for(auto &[s, t] : dx) {
			int x = i + s, y = j + t, z = x * N + y;
 
			if(min(x, y) < 0 || max(x, y) >= N || d[z] != Z) continue;
			if((g[z] & 1 || g[z] == r) && (!r || (d[k] + 1) / S + ans < h[z]))
				d[z] = d[k] + 1, q.push(z);
		}
	}
}

#define gc getchar_unlocked()

void ri(int &I){
	char J = I = 0;
	for(; J < 48; J=gc);
	for(; J > 47; J=gc) I = I * 10 + J - 48;
}
 
signed main(){
	ri(N), ri(S);
 
 	for(int i = 0; i < N; i++, gc)
 		for(int j = 0; j < N; j++)
			g += gc;

	BFS('H', h);

	for(int b = r = 30; --b >= 0; ) {
		ans += 1 << b;
		BFS('M', m);
		if(m[e] == Z)	ans -= 1 << b;
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 84 ms 6008 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 260 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 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 8 ms 1484 KB Output is correct
34 Correct 7 ms 1484 KB Output is correct
35 Correct 20 ms 1484 KB Output is correct
36 Correct 9 ms 1756 KB Output is correct
37 Correct 9 ms 1756 KB Output is correct
38 Correct 26 ms 1756 KB Output is correct
39 Correct 13 ms 2140 KB Output is correct
40 Correct 12 ms 2140 KB Output is correct
41 Correct 33 ms 2200 KB Output is correct
42 Correct 14 ms 2568 KB Output is correct
43 Correct 15 ms 2536 KB Output is correct
44 Correct 41 ms 2572 KB Output is correct
45 Correct 16 ms 3048 KB Output is correct
46 Correct 16 ms 3048 KB Output is correct
47 Correct 53 ms 3048 KB Output is correct
48 Correct 20 ms 3600 KB Output is correct
49 Correct 20 ms 3560 KB Output is correct
50 Correct 61 ms 3560 KB Output is correct
51 Correct 22 ms 4052 KB Output is correct
52 Correct 24 ms 4116 KB Output is correct
53 Correct 76 ms 4072 KB Output is correct
54 Correct 26 ms 4632 KB Output is correct
55 Correct 29 ms 4632 KB Output is correct
56 Correct 105 ms 4628 KB Output is correct
57 Correct 29 ms 5380 KB Output is correct
58 Correct 30 ms 5380 KB Output is correct
59 Correct 98 ms 5336 KB Output is correct
60 Correct 37 ms 6008 KB Output is correct
61 Correct 36 ms 6008 KB Output is correct
62 Correct 113 ms 6012 KB Output is correct
63 Correct 110 ms 6004 KB Output is correct
64 Correct 176 ms 6044 KB Output is correct
65 Correct 157 ms 6012 KB Output is correct
66 Correct 130 ms 6020 KB Output is correct
67 Correct 116 ms 6000 KB Output is correct
68 Correct 67 ms 6000 KB Output is correct
69 Correct 64 ms 6012 KB Output is correct
70 Correct 57 ms 6012 KB Output is correct
71 Correct 46 ms 5992 KB Output is correct
72 Correct 44 ms 6004 KB Output is correct
73 Correct 46 ms 5968 KB Output is correct
74 Correct 63 ms 6020 KB Output is correct
75 Correct 70 ms 6016 KB Output is correct
76 Correct 75 ms 6012 KB Output is correct
77 Correct 67 ms 6084 KB Output is correct
78 Correct 78 ms 6020 KB Output is correct
79 Correct 60 ms 6020 KB Output is correct
80 Correct 72 ms 5980 KB Output is correct
81 Correct 72 ms 6004 KB Output is correct
82 Correct 68 ms 6020 KB Output is correct
83 Correct 80 ms 6008 KB Output is correct
84 Correct 72 ms 6012 KB Output is correct
85 Correct 71 ms 6012 KB Output is correct
86 Correct 79 ms 6020 KB Output is correct
87 Correct 82 ms 6000 KB Output is correct
88 Correct 84 ms 6016 KB Output is correct
89 Correct 77 ms 6052 KB Output is correct
90 Correct 86 ms 6012 KB Output is correct
91 Correct 78 ms 6020 KB Output is correct
92 Correct 79 ms 6004 KB Output is correct