Submission #104022

# Submission time Handle Problem Language Result Execution time Memory
104022 2019-04-03T17:16:10 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};
string maps[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) {
	int curx, cury, curstep, i, i1, movexx, moveyy;
	memset(meStep, -1, sizeof(meStep));
	me.push(mp(Mx * 1000 + My, mid));
	while(!me.empty()) {
		curx = me.front().F / 1000;
		cury = me.front().F % 1000;
		curstep = me.front().S;
		me.pop();
		if(meStep[curx][cury] == -1) {
			meStep[curx][cury] = curstep;
			if(maps[curx][cury] == 'D') {
				while(!me.empty())
					me.pop();
				return true;
			}
			for(i = 0; i < 4; i++) {
				for(i1 = 1; i1 <= s; i1++) {
					movexx = movex[i] * i1 + curx;
					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;
				}
			}
		}
	}
	while(!me.empty())
		me.pop();
	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() {
	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;
	for(i = 0; i < n; i++) {
		cin >> 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()) {
		curx = bee.front().F / 1000;
		cury = bee.front().F % 1000;
		curstep = bee.front().S;
		bee.pop();
		if(beeStep[curx][cury] == -1) {
			beeStep[curx][cury] = curstep;
			for(i = 0; i < 4; i++) {
				movexx = movex[i] + curx;
				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)) {
		cout << "-1\n";
		return 0;
	}
	l = 0; r = n * n;
	while(l + 1 < r) {
		mid = (l + r) / 2;
		if(can(mid)) l = mid;
		else r = mid;
	}
	cout << l << "\n";
	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:55:27: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
  ios_base::sync_with_stdio;
                           ^
mecho.cpp:55:27: warning: statement has no effect [-Wunused-value]
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5376 KB Output isn't correct
2 Incorrect 9 ms 5504 KB Output isn't correct
3 Incorrect 8 ms 5504 KB Output isn't correct
4 Incorrect 8 ms 5504 KB Output isn't correct
5 Correct 7 ms 5504 KB Output is correct
6 Incorrect 7 ms 5504 KB Output isn't correct
7 Execution timed out 1073 ms 19200 KB Time limit exceeded
8 Incorrect 9 ms 5376 KB Output isn't correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 7 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Incorrect 7 ms 5476 KB Output isn't correct
13 Incorrect 8 ms 5376 KB Output isn't correct
14 Correct 7 ms 5504 KB Output is correct
15 Incorrect 9 ms 5504 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 8 ms 5504 KB Output is correct
19 Incorrect 8 ms 5504 KB Output isn't correct
20 Correct 8 ms 5504 KB Output is correct
21 Incorrect 7 ms 5376 KB Output isn't correct
22 Correct 10 ms 5376 KB Output is correct
23 Incorrect 9 ms 5376 KB Output isn't correct
24 Correct 8 ms 5504 KB Output is correct
25 Incorrect 9 ms 5504 KB Output isn't correct
26 Correct 8 ms 5376 KB Output is correct
27 Incorrect 8 ms 5504 KB Output isn't correct
28 Correct 9 ms 5504 KB Output is correct
29 Incorrect 10 ms 5504 KB Output isn't correct
30 Correct 9 ms 5504 KB Output is correct
31 Incorrect 9 ms 5376 KB Output isn't correct
32 Correct 10 ms 5376 KB Output is correct
33 Incorrect 14 ms 5632 KB Output isn't correct
34 Correct 32 ms 5888 KB Output is correct
35 Runtime error 186 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Incorrect 17 ms 5632 KB Output isn't correct
37 Correct 34 ms 6016 KB Output is correct
38 Runtime error 200 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Incorrect 24 ms 5624 KB Output isn't correct
40 Correct 32 ms 6016 KB Output is correct
41 Runtime error 173 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Incorrect 28 ms 6008 KB Output isn't correct
43 Correct 56 ms 6400 KB Output is correct
44 Runtime error 183 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Incorrect 26 ms 5888 KB Output isn't correct
46 Correct 55 ms 6656 KB Output is correct
47 Runtime error 177 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Incorrect 27 ms 6008 KB Output isn't correct
49 Correct 56 ms 6776 KB Output is correct
50 Runtime error 236 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Incorrect 28 ms 6008 KB Output isn't correct
52 Correct 74 ms 7004 KB Output is correct
53 Runtime error 217 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Incorrect 32 ms 6108 KB Output isn't correct
55 Correct 84 ms 7168 KB Output is correct
56 Runtime error 183 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Incorrect 41 ms 6136 KB Output isn't correct
58 Correct 116 ms 7388 KB Output is correct
59 Runtime error 192 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Incorrect 39 ms 6008 KB Output isn't correct
61 Correct 112 ms 7548 KB Output is correct
62 Runtime error 209 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Incorrect 66 ms 6136 KB Output isn't correct
64 Incorrect 306 ms 6296 KB Output isn't correct
65 Incorrect 288 ms 6264 KB Output isn't correct
66 Incorrect 77 ms 6264 KB Output isn't correct
67 Correct 66 ms 6140 KB Output is correct
68 Incorrect 64 ms 6264 KB Output isn't correct
69 Incorrect 59 ms 6152 KB Output isn't correct
70 Incorrect 58 ms 6264 KB Output isn't correct
71 Incorrect 60 ms 6160 KB Output isn't correct
72 Incorrect 64 ms 6136 KB Output isn't correct
73 Incorrect 255 ms 6728 KB Output isn't correct
74 Runtime error 236 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Correct 928 ms 6908 KB Output is correct
76 Correct 497 ms 6724 KB Output is correct
77 Execution timed out 1076 ms 8520 KB Time limit exceeded
78 Correct 218 ms 7160 KB Output is correct
79 Runtime error 228 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Incorrect 782 ms 7160 KB Output isn't correct
81 Incorrect 705 ms 6776 KB Output isn't correct
82 Execution timed out 1065 ms 10104 KB Time limit exceeded
83 Incorrect 179 ms 7160 KB Output isn't correct
84 Runtime error 218 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Execution timed out 1073 ms 9464 KB Time limit exceeded
86 Execution timed out 1074 ms 7672 KB Time limit exceeded
87 Execution timed out 1077 ms 15676 KB Time limit exceeded
88 Incorrect 354 ms 9780 KB Output isn't correct
89 Runtime error 219 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Execution timed out 1067 ms 17672 KB Time limit exceeded
91 Execution timed out 1077 ms 38072 KB Time limit exceeded
92 Execution timed out 1077 ms 11912 KB Time limit exceeded