답안 #104015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104015 2019-04-03T17:00:56 Z Erkhemkhuu Mecho (IOI09_mecho) C++17
15 / 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));
		}
	}
	if(!can(0)) {
		printf("-1\n");
		return 0;
	}
	l = 0; r = n * n;
	while(l + 1 < r) {
		int mid = (l + r) / 2;
		if(can(mid)) l = mid ;
		else r = mid;
	}
	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 7 ms 5376 KB Output isn't correct
2 Incorrect 7 ms 5376 KB Output isn't correct
3 Incorrect 7 ms 5376 KB Output isn't correct
4 Incorrect 7 ms 5376 KB Output isn't correct
5 Correct 7 ms 5376 KB Output is correct
6 Incorrect 7 ms 5376 KB Output isn't correct
7 Execution timed out 1079 ms 19004 KB Time limit exceeded
8 Incorrect 8 ms 5376 KB Output isn't correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 9 ms 5376 KB Output is correct
11 Correct 7 ms 5376 KB Output is correct
12 Incorrect 8 ms 5376 KB Output isn't correct
13 Incorrect 8 ms 5376 KB Output isn't correct
14 Correct 6 ms 5476 KB Output is correct
15 Incorrect 8 ms 5376 KB Output isn't correct
16 Correct 8 ms 5504 KB Output is correct
17 Incorrect 8 ms 5504 KB Output isn't correct
18 Correct 9 ms 5376 KB Output is correct
19 Incorrect 8 ms 5372 KB Output isn't correct
20 Correct 8 ms 5504 KB Output is correct
21 Incorrect 8 ms 5376 KB Output isn't correct
22 Correct 8 ms 5376 KB Output is correct
23 Incorrect 8 ms 5376 KB Output isn't correct
24 Correct 10 ms 5376 KB Output is correct
25 Incorrect 5 ms 5376 KB Output isn't correct
26 Correct 10 ms 5376 KB Output is correct
27 Incorrect 8 ms 5504 KB Output isn't correct
28 Correct 10 ms 5504 KB Output is correct
29 Incorrect 7 ms 5504 KB Output isn't correct
30 Correct 11 ms 5504 KB Output is correct
31 Incorrect 9 ms 5504 KB Output isn't correct
32 Correct 11 ms 5504 KB Output is correct
33 Incorrect 12 ms 5760 KB Output isn't correct
34 Correct 203 ms 6144 KB Output is correct
35 Runtime error 197 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Incorrect 16 ms 5760 KB Output isn't correct
37 Correct 364 ms 6372 KB Output is correct
38 Runtime error 160 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Incorrect 15 ms 5760 KB Output isn't correct
40 Correct 396 ms 6776 KB Output is correct
41 Runtime error 164 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Incorrect 17 ms 5760 KB Output isn't correct
43 Correct 528 ms 7016 KB Output is correct
44 Runtime error 162 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Incorrect 18 ms 5760 KB Output isn't correct
46 Correct 661 ms 7168 KB Output is correct
47 Runtime error 183 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Incorrect 28 ms 5888 KB Output isn't correct
49 Execution timed out 1012 ms 7536 KB Time limit exceeded
50 Runtime error 156 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Incorrect 25 ms 5888 KB Output isn't correct
52 Execution timed out 1076 ms 7672 KB Time limit exceeded
53 Runtime error 160 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Incorrect 27 ms 5888 KB Output isn't correct
55 Execution timed out 1076 ms 8004 KB Time limit exceeded
56 Runtime error 166 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Incorrect 27 ms 6008 KB Output isn't correct
58 Execution timed out 1083 ms 8332 KB Time limit exceeded
59 Runtime error 171 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Incorrect 31 ms 6008 KB Output isn't correct
61 Execution timed out 1063 ms 8576 KB Time limit exceeded
62 Runtime error 188 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Incorrect 46 ms 5968 KB Output isn't correct
64 Incorrect 286 ms 6016 KB Output isn't correct
65 Incorrect 259 ms 6008 KB Output isn't correct
66 Incorrect 49 ms 6008 KB Output isn't correct
67 Correct 57 ms 6008 KB Output is correct
68 Incorrect 36 ms 6008 KB Output isn't correct
69 Incorrect 34 ms 6008 KB Output isn't correct
70 Incorrect 33 ms 6008 KB Output isn't correct
71 Incorrect 33 ms 6008 KB Output isn't correct
72 Incorrect 43 ms 6008 KB Output isn't correct
73 Incorrect 216 ms 6600 KB Output isn't correct
74 Runtime error 221 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Correct 712 ms 6652 KB Output is correct
76 Correct 444 ms 6544 KB Output is correct
77 Execution timed out 1090 ms 8288 KB Time limit exceeded
78 Correct 166 ms 7032 KB Output is correct
79 Runtime error 236 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Incorrect 678 ms 7164 KB Output isn't correct
81 Incorrect 652 ms 6576 KB Output isn't correct
82 Execution timed out 1083 ms 9848 KB Time limit exceeded
83 Incorrect 141 ms 6904 KB Output isn't correct
84 Runtime error 194 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Execution timed out 1067 ms 9404 KB Time limit exceeded
86 Execution timed out 1087 ms 7544 KB Time limit exceeded
87 Execution timed out 1082 ms 15484 KB Time limit exceeded
88 Incorrect 302 ms 9464 KB Output isn't correct
89 Runtime error 202 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Execution timed out 1078 ms 17404 KB Time limit exceeded
91 Execution timed out 1087 ms 37816 KB Time limit exceeded
92 Execution timed out 1065 ms 11856 KB Time limit exceeded