답안 #104094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104094 2019-04-04T02:40:05 Z Erkhemkhuu Mecho (IOI09_mecho) C++17
100 / 100
302 ms 6492 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;
	me.push(mp(Mx, My));
	memset(meStep, -1, sizeof(meStep));
	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 5504 KB Output is correct
3 Correct 8 ms 5376 KB Output is correct
4 Correct 8 ms 5504 KB Output is correct
5 Correct 7 ms 5376 KB Output is correct
6 Correct 8 ms 5504 KB Output is correct
7 Correct 166 ms 6240 KB Output is correct
8 Correct 7 ms 5504 KB Output is correct
9 Correct 8 ms 5504 KB Output is correct
10 Correct 8 ms 5504 KB Output is correct
11 Correct 8 ms 5376 KB Output is correct
12 Correct 7 ms 5504 KB Output is correct
13 Correct 7 ms 5504 KB Output is correct
14 Correct 8 ms 5504 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 8 ms 5504 KB Output is correct
17 Correct 8 ms 5504 KB Output is correct
18 Correct 6 ms 5376 KB Output is correct
19 Correct 7 ms 5504 KB Output is correct
20 Correct 8 ms 5376 KB Output is correct
21 Correct 9 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 7 ms 5508 KB Output is correct
25 Correct 8 ms 5504 KB Output is correct
26 Correct 8 ms 5504 KB Output is correct
27 Correct 7 ms 5504 KB Output is correct
28 Correct 7 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 9 ms 5504 KB Output is correct
33 Correct 12 ms 5760 KB Output is correct
34 Correct 12 ms 5760 KB Output is correct
35 Correct 36 ms 5632 KB Output is correct
36 Correct 11 ms 5760 KB Output is correct
37 Correct 11 ms 5760 KB Output is correct
38 Correct 54 ms 5884 KB Output is correct
39 Correct 11 ms 5760 KB Output is correct
40 Correct 10 ms 5760 KB Output is correct
41 Correct 61 ms 5760 KB Output is correct
42 Correct 12 ms 5888 KB Output is correct
43 Correct 12 ms 5760 KB Output is correct
44 Correct 78 ms 5888 KB Output is correct
45 Correct 13 ms 5888 KB Output is correct
46 Correct 13 ms 5888 KB Output is correct
47 Correct 90 ms 6008 KB Output is correct
48 Correct 12 ms 5888 KB Output is correct
49 Correct 14 ms 5888 KB Output is correct
50 Correct 121 ms 5980 KB Output is correct
51 Correct 19 ms 5888 KB Output is correct
52 Correct 21 ms 6008 KB Output is correct
53 Correct 142 ms 6008 KB Output is correct
54 Correct 16 ms 6016 KB Output is correct
55 Correct 20 ms 6016 KB Output is correct
56 Correct 164 ms 6008 KB Output is correct
57 Correct 16 ms 6012 KB Output is correct
58 Correct 18 ms 6016 KB Output is correct
59 Correct 177 ms 6008 KB Output is correct
60 Correct 38 ms 6008 KB Output is correct
61 Correct 21 ms 6016 KB Output is correct
62 Correct 218 ms 6136 KB Output is correct
63 Correct 136 ms 6136 KB Output is correct
64 Correct 302 ms 6196 KB Output is correct
65 Correct 227 ms 6136 KB Output is correct
66 Correct 189 ms 6012 KB Output is correct
67 Correct 48 ms 6008 KB Output is correct
68 Correct 76 ms 6136 KB Output is correct
69 Correct 70 ms 6136 KB Output is correct
70 Correct 64 ms 6008 KB Output is correct
71 Correct 54 ms 6008 KB Output is correct
72 Correct 48 ms 6012 KB Output is correct
73 Correct 47 ms 6400 KB Output is correct
74 Correct 106 ms 6392 KB Output is correct
75 Correct 119 ms 6252 KB Output is correct
76 Correct 123 ms 6392 KB Output is correct
77 Correct 117 ms 6492 KB Output is correct
78 Correct 40 ms 6264 KB Output is correct
79 Correct 82 ms 6264 KB Output is correct
80 Correct 85 ms 6264 KB Output is correct
81 Correct 117 ms 6264 KB Output is correct
82 Correct 84 ms 6236 KB Output is correct
83 Correct 196 ms 6264 KB Output is correct
84 Correct 129 ms 6368 KB Output is correct
85 Correct 131 ms 6264 KB Output is correct
86 Correct 139 ms 6304 KB Output is correct
87 Correct 123 ms 6264 KB Output is correct
88 Correct 122 ms 6364 KB Output is correct
89 Correct 154 ms 6264 KB Output is correct
90 Correct 158 ms 6264 KB Output is correct
91 Correct 148 ms 6136 KB Output is correct
92 Correct 143 ms 6392 KB Output is correct