답안 #501346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501346 2022-01-02T20:43:02 Z sidon Mecho (IOI09_mecho) C++17
100 / 100
177 ms 6136 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);
		}
	}
}
 
signed main(){
	cin >> N >> S;
 
 	for(int i = 0; i < N; i++)
 		cin >> _, g += _;

	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 0 ms 204 KB Output is correct
7 Correct 88 ms 6056 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 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 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 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 1440 KB Output is correct
34 Correct 9 ms 1440 KB Output is correct
35 Correct 20 ms 1440 KB Output is correct
36 Correct 10 ms 1800 KB Output is correct
37 Correct 11 ms 1800 KB Output is correct
38 Correct 26 ms 1800 KB Output is correct
39 Correct 13 ms 2212 KB Output is correct
40 Correct 14 ms 2160 KB Output is correct
41 Correct 34 ms 2160 KB Output is correct
42 Correct 18 ms 2644 KB Output is correct
43 Correct 18 ms 2644 KB Output is correct
44 Correct 41 ms 2560 KB Output is correct
45 Correct 19 ms 3108 KB Output is correct
46 Correct 20 ms 3108 KB Output is correct
47 Correct 53 ms 3108 KB Output is correct
48 Correct 26 ms 3620 KB Output is correct
49 Correct 23 ms 3600 KB Output is correct
50 Correct 61 ms 3560 KB Output is correct
51 Correct 27 ms 4160 KB Output is correct
52 Correct 28 ms 4160 KB Output is correct
53 Correct 78 ms 4044 KB Output is correct
54 Correct 32 ms 4644 KB Output is correct
55 Correct 33 ms 4640 KB Output is correct
56 Correct 87 ms 4628 KB Output is correct
57 Correct 42 ms 5344 KB Output is correct
58 Correct 42 ms 5264 KB Output is correct
59 Correct 103 ms 5280 KB Output is correct
60 Correct 40 ms 5976 KB Output is correct
61 Correct 42 ms 6016 KB Output is correct
62 Correct 120 ms 6056 KB Output is correct
63 Correct 113 ms 6008 KB Output is correct
64 Correct 177 ms 6136 KB Output is correct
65 Correct 169 ms 6044 KB Output is correct
66 Correct 133 ms 6004 KB Output is correct
67 Correct 124 ms 6008 KB Output is correct
68 Correct 70 ms 6048 KB Output is correct
69 Correct 67 ms 6048 KB Output is correct
70 Correct 59 ms 6000 KB Output is correct
71 Correct 53 ms 6012 KB Output is correct
72 Correct 52 ms 6008 KB Output is correct
73 Correct 52 ms 6008 KB Output is correct
74 Correct 71 ms 6028 KB Output is correct
75 Correct 76 ms 6036 KB Output is correct
76 Correct 74 ms 6084 KB Output is correct
77 Correct 74 ms 6048 KB Output is correct
78 Correct 85 ms 6008 KB Output is correct
79 Correct 69 ms 6056 KB Output is correct
80 Correct 74 ms 6000 KB Output is correct
81 Correct 85 ms 6056 KB Output is correct
82 Correct 75 ms 6056 KB Output is correct
83 Correct 86 ms 6004 KB Output is correct
84 Correct 78 ms 6012 KB Output is correct
85 Correct 77 ms 6048 KB Output is correct
86 Correct 82 ms 6008 KB Output is correct
87 Correct 85 ms 6048 KB Output is correct
88 Correct 84 ms 6008 KB Output is correct
89 Correct 87 ms 5972 KB Output is correct
90 Correct 88 ms 6048 KB Output is correct
91 Correct 86 ms 6004 KB Output is correct
92 Correct 84 ms 6012 KB Output is correct