답안 #501141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501141 2022-01-02T13:04:26 Z sidon Mecho (IOI09_mecho) C++17
29 / 100
203 ms 6776 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, 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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Correct 1 ms 412 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 91 ms 6700 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 344 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 1 ms 444 KB Output isn't correct
15 Incorrect 0 ms 352 KB Output isn't correct
16 Correct 0 ms 352 KB Output is correct
17 Incorrect 0 ms 352 KB Output isn't correct
18 Correct 1 ms 332 KB Output is correct
19 Incorrect 0 ms 332 KB Output isn't correct
20 Correct 0 ms 332 KB Output is correct
21 Incorrect 0 ms 332 KB Output isn't correct
22 Correct 0 ms 332 KB Output is correct
23 Incorrect 1 ms 332 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 356 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 356 KB Output isn't correct
30 Correct 1 ms 332 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 7 ms 1484 KB Output isn't correct
34 Correct 9 ms 1560 KB Output is correct
35 Correct 24 ms 1484 KB Output is correct
36 Incorrect 9 ms 1892 KB Output isn't correct
37 Correct 9 ms 1892 KB Output is correct
38 Correct 30 ms 1896 KB Output is correct
39 Incorrect 11 ms 2280 KB Output isn't correct
40 Correct 12 ms 2276 KB Output is correct
41 Correct 39 ms 2280 KB Output is correct
42 Incorrect 15 ms 2756 KB Output isn't correct
43 Correct 15 ms 2816 KB Output is correct
44 Correct 48 ms 2712 KB Output is correct
45 Incorrect 17 ms 3284 KB Output isn't correct
46 Correct 16 ms 3312 KB Output is correct
47 Correct 66 ms 3424 KB Output is correct
48 Incorrect 19 ms 3916 KB Output isn't correct
49 Correct 20 ms 3780 KB Output is correct
50 Correct 74 ms 3816 KB Output is correct
51 Incorrect 23 ms 4452 KB Output isn't correct
52 Correct 28 ms 4428 KB Output is correct
53 Correct 92 ms 4504 KB Output is correct
54 Incorrect 27 ms 5180 KB Output isn't correct
55 Correct 30 ms 5068 KB Output is correct
56 Correct 102 ms 5172 KB Output is correct
57 Incorrect 30 ms 5856 KB Output isn't correct
58 Correct 29 ms 5880 KB Output is correct
59 Correct 120 ms 5824 KB Output is correct
60 Incorrect 38 ms 6592 KB Output isn't correct
61 Correct 35 ms 6648 KB Output is correct
62 Correct 144 ms 6572 KB Output is correct
63 Correct 120 ms 6592 KB Output is correct
64 Correct 203 ms 6648 KB Output is correct
65 Correct 196 ms 6592 KB Output is correct
66 Incorrect 150 ms 6608 KB Output isn't correct
67 Incorrect 143 ms 6584 KB Output isn't correct
68 Correct 65 ms 6672 KB Output is correct
69 Correct 60 ms 6628 KB Output is correct
70 Correct 56 ms 6660 KB Output is correct
71 Correct 53 ms 6660 KB Output is correct
72 Incorrect 46 ms 6624 KB Output isn't correct
73 Incorrect 48 ms 6756 KB Output isn't correct
74 Correct 69 ms 6712 KB Output is correct
75 Correct 73 ms 6720 KB Output is correct
76 Correct 76 ms 6732 KB Output is correct
77 Correct 74 ms 6708 KB Output is correct
78 Incorrect 92 ms 6772 KB Output isn't correct
79 Correct 67 ms 6772 KB Output is correct
80 Correct 74 ms 6776 KB Output is correct
81 Correct 77 ms 6720 KB Output is correct
82 Correct 72 ms 6760 KB Output is correct
83 Correct 84 ms 6724 KB Output is correct
84 Correct 86 ms 6724 KB Output is correct
85 Correct 76 ms 6724 KB Output is correct
86 Correct 83 ms 6752 KB Output is correct
87 Correct 80 ms 6732 KB Output is correct
88 Correct 86 ms 6732 KB Output is correct
89 Correct 89 ms 6728 KB Output is correct
90 Correct 94 ms 6724 KB Output is correct
91 Correct 86 ms 6668 KB Output is correct
92 Correct 86 ms 6724 KB Output is correct