답안 #104009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104009 2019-04-03T16:45:31 Z Erkhemkhuu Mecho (IOI09_mecho) C++17
11 / 100
1000 ms 66560 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;
}
bool can(int mid) {
	memset(meStep, -1, sizeof(meStep));
	me.push(mp(Mx * 1000 + My, mid));
	while(!me.empty()) {
		int curx = me.front().F / 1000;
		int cury = me.front().F % 1000;
		int curstep = me.front().S;
		me.pop();
		if(meStep[curx][cury] != -1) continue;
		meStep[curx][cury] = curstep;
		for(int i = 0; i < 4; i++) {
			for(int i1 = 1; i1 <= s; i1++) {
				int movexx = movex[i] * i1 + curx;
				int moveyy = movey[i] * i1 + cury;
				if(check(movexx, moveyy) && maps[movexx][moveyy] != 'T' && meStep[movexx][moveyy] == -1) {
					if(beeStep[movexx][moveyy] != -1 && beeStep[movexx][moveyy] <= curstep) break;
					me.push(mp(movexx * 1000 + moveyy, curstep + 1));
				}
				else break;
			}
		}
	}
	//cout << meStep[Dx][Dy] << " " << beeStep[Dx][Dy] << "\n";
	if(beeStep[Dx][Dy] == -1) beeStep[Dx][Dy] = 1e9;
	if(meStep[Dx][Dy] == -1) return false;
	return meStep[Dx][Dy] <= beeStep[Dx][Dy];
}
int main() { 
	int i, j, l, r;
	scanf("%d%d", &n, &s);
	for(i = 0; i < n; i++) {
		scanf("%s", maps[i]);
		for(j = 0; j < n; j++) {
			if(maps[i][j] == 'H')
				bee.push(mp(i * 1000 + j, 0));
			if(maps[i][j] == 'M') {
				Mx = i; My = j;
			}
			if(maps[i][j] == 'D') {
				Dx = i; Dy = j;
			}
		}
	}
	memset(beeStep, -1, sizeof(beeStep));
	while(!bee.empty()) {
		int curx = bee.front().F / 1000;
		int cury = bee.front().F % 1000;
		int curstep = bee.front().S;
		bee.pop();
		if(beeStep[curx][cury] != -1) continue;
		beeStep[curx][cury] = curstep;
		for(int i = 0; i < 4; i++) {
			int movexx = movex[i] + curx;
			int moveyy = movey[i] + cury;
			if(check(movexx, moveyy) && maps[movexx][moveyy] != 'T' && beeStep[movexx][moveyy] == -1)
				bee.push(mp(movexx * 1000 + moveyy, curstep + 1));
		}
	}
	l = 0; r = 1e9;
	while(l != r) {
		int mid = (l + r + 1) / 2;
		if(can(mid)) l = mid ;
		else r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &s);
  ~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", maps[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 5376 KB Output isn't correct
2 Incorrect 11 ms 5248 KB Output isn't correct
3 Incorrect 12 ms 5624 KB Output isn't correct
4 Incorrect 10 ms 5376 KB Output isn't correct
5 Correct 12 ms 5504 KB Output is correct
6 Incorrect 10 ms 5376 KB Output isn't correct
7 Execution timed out 1069 ms 16476 KB Time limit exceeded
8 Incorrect 10 ms 5376 KB Output isn't correct
9 Correct 11 ms 5504 KB Output is correct
10 Correct 10 ms 5376 KB Output is correct
11 Correct 9 ms 5376 KB Output is correct
12 Incorrect 11 ms 5376 KB Output isn't correct
13 Incorrect 11 ms 5376 KB Output isn't correct
14 Incorrect 13 ms 5504 KB Output isn't correct
15 Incorrect 11 ms 5376 KB Output isn't correct
16 Correct 10 ms 5376 KB Output is correct
17 Incorrect 10 ms 5376 KB Output isn't correct
18 Correct 10 ms 5476 KB Output is correct
19 Incorrect 12 ms 5472 KB Output isn't correct
20 Correct 12 ms 5504 KB Output is correct
21 Incorrect 10 ms 5504 KB Output isn't correct
22 Correct 10 ms 5504 KB Output is correct
23 Incorrect 10 ms 5376 KB Output isn't correct
24 Correct 10 ms 5376 KB Output is correct
25 Incorrect 11 ms 5504 KB Output isn't correct
26 Correct 12 ms 5504 KB Output is correct
27 Incorrect 11 ms 5504 KB Output isn't correct
28 Correct 11 ms 5504 KB Output is correct
29 Incorrect 10 ms 5504 KB Output isn't correct
30 Correct 11 ms 5504 KB Output is correct
31 Incorrect 11 ms 5504 KB Output isn't correct
32 Correct 11 ms 5504 KB Output is correct
33 Incorrect 14 ms 5760 KB Output isn't correct
34 Correct 101 ms 6224 KB Output is correct
35 Runtime error 554 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Incorrect 13 ms 5760 KB Output isn't correct
37 Correct 61 ms 6468 KB Output is correct
38 Runtime error 313 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Incorrect 16 ms 5760 KB Output isn't correct
40 Correct 131 ms 6620 KB Output is correct
41 Runtime error 416 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Incorrect 18 ms 5760 KB Output isn't correct
43 Correct 44 ms 6784 KB Output is correct
44 Runtime error 368 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Incorrect 16 ms 5760 KB Output isn't correct
46 Correct 191 ms 7288 KB Output is correct
47 Runtime error 262 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Incorrect 17 ms 5888 KB Output isn't correct
49 Correct 344 ms 7388 KB Output is correct
50 Runtime error 314 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Incorrect 21 ms 5888 KB Output isn't correct
52 Correct 496 ms 7704 KB Output is correct
53 Runtime error 182 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Incorrect 28 ms 5888 KB Output isn't correct
55 Correct 831 ms 8068 KB Output is correct
56 Runtime error 167 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Incorrect 25 ms 6016 KB Output isn't correct
58 Correct 267 ms 8444 KB Output is correct
59 Runtime error 172 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Incorrect 24 ms 6016 KB Output isn't correct
61 Correct 420 ms 8704 KB Output is correct
62 Runtime error 187 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Correct 128 ms 6008 KB Output is correct
64 Incorrect 268 ms 6140 KB Output isn't correct
65 Incorrect 209 ms 6008 KB Output isn't correct
66 Incorrect 165 ms 6240 KB Output isn't correct
67 Incorrect 168 ms 6108 KB Output isn't correct
68 Correct 37 ms 6100 KB Output is correct
69 Incorrect 38 ms 6096 KB Output isn't correct
70 Incorrect 42 ms 6004 KB Output isn't correct
71 Incorrect 41 ms 6008 KB Output isn't correct
72 Incorrect 41 ms 5980 KB Output isn't correct
73 Incorrect 230 ms 6700 KB Output isn't correct
74 Runtime error 251 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Correct 657 ms 6608 KB Output is correct
76 Correct 398 ms 6596 KB Output is correct
77 Execution timed out 1068 ms 7692 KB Time limit exceeded
78 Incorrect 908 ms 7276 KB Output isn't correct
79 Runtime error 271 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Incorrect 646 ms 7180 KB Output isn't correct
81 Incorrect 535 ms 6620 KB Output isn't correct
82 Execution timed out 1036 ms 8884 KB Time limit exceeded
83 Correct 851 ms 7188 KB Output is correct
84 Runtime error 342 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Execution timed out 1056 ms 9216 KB Time limit exceeded
86 Execution timed out 1073 ms 7636 KB Time limit exceeded
87 Execution timed out 1078 ms 14208 KB Time limit exceeded
88 Execution timed out 1075 ms 9628 KB Time limit exceeded
89 Runtime error 192 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Execution timed out 1077 ms 16008 KB Time limit exceeded
91 Execution timed out 1063 ms 30632 KB Time limit exceeded
92 Execution timed out 1069 ms 11488 KB Time limit exceeded