답안 #104095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104095 2019-04-04T02:42:08 Z Erkhemkhuu Mecho (IOI09_mecho) C++17
100 / 100
270 ms 6528 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
int movex[4] = {-1, 0, 1, 0};
int movey[4] = {0, 1, 0, -1};
char maps[805][805];
int beeStep[805][805], meStep[805][805], n, Mx, My, s, Dx, Dy;
queue <pair <int, int> > bee, me;
inline bool check(int x, int y) {
	if(x >= 0 && x < n && y >= 0 && y < n) return true;
	return false;
}
inline bool can(int mid) {
	if(mid >= beeStep[Mx][My]) return false;
	int curx, cury, i, j, i1, movexx, moveyy;
	memset(meStep, -1, sizeof(meStep));
	me.push(mp(Mx, My));
	meStep[Mx][My] = 0;
	while(!me.empty()) {
		curx = me.front().F;
		cury = me.front().S;
		me.pop();
		for(i = 0; i < 4; i++) {
			movexx = movex[i] + curx;
			moveyy = movey[i] + cury;
			if(check(movexx, moveyy) && maps[movexx][moveyy] == 'D') {
				while(!me.empty())
					me.pop();
				return true;	
			}
			if(check(movexx, moveyy) && (maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'D') && meStep[curx][cury] + 1 < s * (beeStep[movexx][moveyy] - mid) && meStep[movexx][moveyy] == -1) {
				meStep[movexx][moveyy] = meStep[curx][cury] + 1;
				me.push(mp(movexx, moveyy));
			} 
		}
	}
	return false;
}
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(NULL);
	int i, j, l, r, curx, cury, curstep, movexx, moveyy, mid;
	cin >> n >> s;
	memset(beeStep, -1, sizeof(beeStep));
	for(i = 0; i < n; i++) {
		cin >> maps[i];
		for(j = 0; j < n; j++) {
			if(maps[i][j] == 'H') {
				bee.push(mp(i, j));
				beeStep[i][j] = 0;
			}
			if(maps[i][j] == 'M') {
				Mx = i; My = j;
			}
			if(maps[i][j] == 'D') {
				Dx = i; Dy = j;
			}
		}
	}
	while(!bee.empty()) {
		curx = bee.front().F;
		cury = bee.front().S;
		bee.pop();
		for(i = 0; i < 4; i++) {
			movexx = movex[i] + curx;
			moveyy = movey[i] + cury;
			if((check(movexx, moveyy) && maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'M') && beeStep[movexx][moveyy] == -1) {
				beeStep[movexx][moveyy] = beeStep[curx][cury] + 1;
				bee.push(mp(movexx, moveyy));
			}
		}
	}
	if(!can(0)) {
		cout << "-1\n";
		return 0;
	}
	l = 0; r = n * n;
	while(l != r) {
		mid = (l + r + 1) / 2;
		if(can(mid)) l = mid;
		else r = mid - 1;
	}
	cout << l << "\n";
	return 0;
}

Compilation message

mecho.cpp: In function 'bool can(int)':
mecho.cpp:19:21: warning: unused variable 'j' [-Wunused-variable]
  int curx, cury, i, j, i1, movexx, moveyy;
                     ^
mecho.cpp:19:24: warning: unused variable 'i1' [-Wunused-variable]
  int curx, cury, i, j, i1, movexx, moveyy;
                        ^~
mecho.cpp: In function 'int main()':
mecho.cpp:72:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if((check(movexx, moveyy) && maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'M') && beeStep[movexx][moveyy] == -1) {
        ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:47:30: warning: unused variable 'curstep' [-Wunused-variable]
  int i, j, l, r, curx, cury, curstep, movexx, moveyy, mid;
                              ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5504 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 7 ms 5504 KB Output is correct
4 Correct 6 ms 5376 KB Output is correct
5 Correct 6 ms 5376 KB Output is correct
6 Correct 7 ms 5376 KB Output is correct
7 Correct 139 ms 6216 KB Output is correct
8 Correct 6 ms 5404 KB Output is correct
9 Correct 7 ms 5504 KB Output is correct
10 Correct 7 ms 5504 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5504 KB Output is correct
13 Correct 8 ms 5504 KB Output is correct
14 Correct 7 ms 5504 KB Output is correct
15 Correct 7 ms 5376 KB Output is correct
16 Correct 6 ms 5376 KB Output is correct
17 Correct 8 ms 5504 KB Output is correct
18 Correct 7 ms 5376 KB Output is correct
19 Correct 8 ms 5376 KB Output is correct
20 Correct 7 ms 5504 KB Output is correct
21 Correct 8 ms 5504 KB Output is correct
22 Correct 7 ms 5504 KB Output is correct
23 Correct 8 ms 5504 KB Output is correct
24 Correct 9 ms 5504 KB Output is correct
25 Correct 8 ms 5504 KB Output is correct
26 Correct 8 ms 5504 KB Output is correct
27 Correct 8 ms 5504 KB Output is correct
28 Correct 9 ms 5504 KB Output is correct
29 Correct 7 ms 5504 KB Output is correct
30 Correct 8 ms 5504 KB Output is correct
31 Correct 7 ms 5504 KB Output is correct
32 Correct 8 ms 5504 KB Output is correct
33 Correct 11 ms 5760 KB Output is correct
34 Correct 10 ms 5760 KB Output is correct
35 Correct 35 ms 5760 KB Output is correct
36 Correct 11 ms 5760 KB Output is correct
37 Correct 13 ms 5760 KB Output is correct
38 Correct 55 ms 5760 KB Output is correct
39 Correct 11 ms 5760 KB Output is correct
40 Correct 12 ms 5760 KB Output is correct
41 Correct 72 ms 5824 KB Output is correct
42 Correct 16 ms 5760 KB Output is correct
43 Correct 15 ms 5888 KB Output is correct
44 Correct 80 ms 5760 KB Output is correct
45 Correct 14 ms 5888 KB Output is correct
46 Correct 13 ms 5888 KB Output is correct
47 Correct 104 ms 5888 KB Output is correct
48 Correct 17 ms 5888 KB Output is correct
49 Correct 14 ms 5888 KB Output is correct
50 Correct 116 ms 6048 KB Output is correct
51 Correct 17 ms 6016 KB Output is correct
52 Correct 17 ms 5888 KB Output is correct
53 Correct 126 ms 5988 KB Output is correct
54 Correct 16 ms 6016 KB Output is correct
55 Correct 25 ms 6016 KB Output is correct
56 Correct 138 ms 6008 KB Output is correct
57 Correct 16 ms 6016 KB Output is correct
58 Correct 19 ms 6016 KB Output is correct
59 Correct 174 ms 6008 KB Output is correct
60 Correct 18 ms 6100 KB Output is correct
61 Correct 20 ms 6016 KB Output is correct
62 Correct 197 ms 6144 KB Output is correct
63 Correct 144 ms 6008 KB Output is correct
64 Correct 270 ms 6008 KB Output is correct
65 Correct 213 ms 6008 KB Output is correct
66 Correct 188 ms 6016 KB Output is correct
67 Correct 44 ms 6136 KB Output is correct
68 Correct 83 ms 6136 KB Output is correct
69 Correct 73 ms 6136 KB Output is correct
70 Correct 74 ms 6136 KB Output is correct
71 Correct 56 ms 6024 KB Output is correct
72 Correct 38 ms 6136 KB Output is correct
73 Correct 51 ms 6264 KB Output is correct
74 Correct 105 ms 6528 KB Output is correct
75 Correct 109 ms 6264 KB Output is correct
76 Correct 127 ms 6264 KB Output is correct
77 Correct 127 ms 6392 KB Output is correct
78 Correct 41 ms 6276 KB Output is correct
79 Correct 89 ms 6264 KB Output is correct
80 Correct 109 ms 6392 KB Output is correct
81 Correct 111 ms 6264 KB Output is correct
82 Correct 116 ms 6264 KB Output is correct
83 Correct 131 ms 6304 KB Output is correct
84 Correct 124 ms 6368 KB Output is correct
85 Correct 156 ms 6312 KB Output is correct
86 Correct 163 ms 6264 KB Output is correct
87 Correct 107 ms 6264 KB Output is correct
88 Correct 137 ms 6264 KB Output is correct
89 Correct 153 ms 6136 KB Output is correct
90 Correct 149 ms 6268 KB Output is correct
91 Correct 183 ms 6392 KB Output is correct
92 Correct 129 ms 6264 KB Output is correct