답안 #104093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104093 2019-04-04T02:37:50 Z Erkhemkhuu Mecho (IOI09_mecho) C++17
100 / 100
299 ms 6392 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;
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, curstep, i, j, i1, movexx, moveyy;
	me.push(mp(Mx, My));
	for(i = 0; i < n; i++) 
		for(j = 0; j < n; j++) 
			meStep[i][j] = 1e9;
	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] == 1e9) {
				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;
	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:18: warning: unused variable 'curstep' [-Wunused-variable]
  int curx, cury, curstep, i, j, i1, movexx, moveyy;
                  ^~~~~~~
mecho.cpp:19:33: warning: unused variable 'i1' [-Wunused-variable]
  int curx, cury, curstep, i, j, i1, movexx, moveyy;
                                 ^~
mecho.cpp: In function 'int main()':
mecho.cpp:48:27: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
  ios_base::sync_with_stdio;
                           ^
mecho.cpp:48:27: warning: statement has no effect [-Wunused-value]
mecho.cpp:74: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:49:30: warning: unused variable 'curstep' [-Wunused-variable]
  int i, j, l, r, curx, cury, curstep, movexx, moveyy, mid;
                              ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2816 KB Output is correct
2 Correct 4 ms 2944 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Correct 4 ms 2944 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 5 ms 2944 KB Output is correct
7 Correct 178 ms 6136 KB Output is correct
8 Correct 4 ms 2944 KB Output is correct
9 Correct 5 ms 2944 KB Output is correct
10 Correct 5 ms 2944 KB Output is correct
11 Correct 5 ms 2944 KB Output is correct
12 Correct 5 ms 3072 KB Output is correct
13 Correct 4 ms 3072 KB Output is correct
14 Correct 4 ms 3072 KB Output is correct
15 Correct 4 ms 2944 KB Output is correct
16 Correct 4 ms 2944 KB Output is correct
17 Correct 4 ms 2944 KB Output is correct
18 Correct 4 ms 2944 KB Output is correct
19 Correct 5 ms 2944 KB Output is correct
20 Correct 5 ms 2944 KB Output is correct
21 Correct 5 ms 3072 KB Output is correct
22 Correct 4 ms 3072 KB Output is correct
23 Correct 4 ms 3072 KB Output is correct
24 Correct 4 ms 3072 KB Output is correct
25 Correct 5 ms 3072 KB Output is correct
26 Correct 5 ms 3072 KB Output is correct
27 Correct 4 ms 3072 KB Output is correct
28 Correct 5 ms 3072 KB Output is correct
29 Correct 5 ms 3200 KB Output is correct
30 Correct 6 ms 3200 KB Output is correct
31 Correct 4 ms 3200 KB Output is correct
32 Correct 5 ms 3200 KB Output is correct
33 Correct 14 ms 4224 KB Output is correct
34 Correct 13 ms 4196 KB Output is correct
35 Correct 40 ms 4352 KB Output is correct
36 Correct 14 ms 4480 KB Output is correct
37 Correct 14 ms 4480 KB Output is correct
38 Correct 63 ms 4528 KB Output is correct
39 Correct 14 ms 4608 KB Output is correct
40 Correct 16 ms 4608 KB Output is correct
41 Correct 55 ms 4608 KB Output is correct
42 Correct 23 ms 4856 KB Output is correct
43 Correct 26 ms 4864 KB Output is correct
44 Correct 80 ms 4956 KB Output is correct
45 Correct 23 ms 5112 KB Output is correct
46 Correct 28 ms 5112 KB Output is correct
47 Correct 88 ms 4992 KB Output is correct
48 Correct 31 ms 5248 KB Output is correct
49 Correct 26 ms 5240 KB Output is correct
50 Correct 122 ms 5368 KB Output is correct
51 Correct 27 ms 5368 KB Output is correct
52 Correct 33 ms 5496 KB Output is correct
53 Correct 150 ms 5476 KB Output is correct
54 Correct 31 ms 5624 KB Output is correct
55 Correct 36 ms 5632 KB Output is correct
56 Correct 167 ms 5752 KB Output is correct
57 Correct 38 ms 5880 KB Output is correct
58 Correct 36 ms 5752 KB Output is correct
59 Correct 177 ms 6008 KB Output is correct
60 Correct 35 ms 6016 KB Output is correct
61 Correct 41 ms 6016 KB Output is correct
62 Correct 227 ms 6100 KB Output is correct
63 Correct 188 ms 6136 KB Output is correct
64 Correct 299 ms 6008 KB Output is correct
65 Correct 216 ms 6008 KB Output is correct
66 Correct 189 ms 6008 KB Output is correct
67 Correct 56 ms 6008 KB Output is correct
68 Correct 86 ms 6112 KB Output is correct
69 Correct 94 ms 6136 KB Output is correct
70 Correct 88 ms 6036 KB Output is correct
71 Correct 72 ms 6008 KB Output is correct
72 Correct 54 ms 6008 KB Output is correct
73 Correct 78 ms 6392 KB Output is correct
74 Correct 102 ms 6240 KB Output is correct
75 Correct 115 ms 6236 KB Output is correct
76 Correct 107 ms 6264 KB Output is correct
77 Correct 119 ms 6264 KB Output is correct
78 Correct 67 ms 6224 KB Output is correct
79 Correct 103 ms 6216 KB Output is correct
80 Correct 120 ms 6264 KB Output is correct
81 Correct 130 ms 6364 KB Output is correct
82 Correct 122 ms 6308 KB Output is correct
83 Correct 147 ms 6172 KB Output is correct
84 Correct 139 ms 6272 KB Output is correct
85 Correct 143 ms 6392 KB Output is correct
86 Correct 167 ms 6264 KB Output is correct
87 Correct 143 ms 6264 KB Output is correct
88 Correct 158 ms 6188 KB Output is correct
89 Correct 171 ms 6248 KB Output is correct
90 Correct 160 ms 6136 KB Output is correct
91 Correct 153 ms 6236 KB Output is correct
92 Correct 176 ms 6264 KB Output is correct