Submission #104014

# Submission time Handle Problem Language Result Execution time Memory
104014 2019-04-03T16:59:31 Z Erkhemkhuu Mecho (IOI09_mecho) C++17
25 / 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]);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5504 KB Output is correct
2 Incorrect 6 ms 5376 KB Output isn't correct
3 Correct 7 ms 5376 KB Output is correct
4 Incorrect 6 ms 5376 KB Output isn't correct
5 Incorrect 7 ms 5376 KB Output isn't correct
6 Incorrect 6 ms 5376 KB Output isn't correct
7 Execution timed out 1076 ms 19208 KB Time limit exceeded
8 Correct 6 ms 5376 KB Output is correct
9 Incorrect 6 ms 5376 KB Output isn't correct
10 Incorrect 7 ms 5376 KB Output isn't correct
11 Incorrect 8 ms 5504 KB Output isn't correct
12 Incorrect 6 ms 5376 KB Output isn't correct
13 Incorrect 9 ms 5504 KB Output isn't correct
14 Correct 7 ms 5504 KB Output is correct
15 Correct 7 ms 5504 KB Output is correct
16 Correct 8 ms 5504 KB Output is correct
17 Correct 7 ms 5504 KB Output is correct
18 Correct 9 ms 5504 KB Output is correct
19 Correct 7 ms 5504 KB Output is correct
20 Correct 9 ms 5504 KB Output is correct
21 Correct 8 ms 5424 KB Output is correct
22 Correct 9 ms 5376 KB Output is correct
23 Correct 8 ms 5504 KB Output is correct
24 Correct 10 ms 5504 KB Output is correct
25 Correct 8 ms 5376 KB Output is correct
26 Correct 10 ms 5504 KB Output is correct
27 Correct 10 ms 5504 KB Output is correct
28 Correct 10 ms 5432 KB Output is correct
29 Correct 9 ms 5504 KB Output is correct
30 Correct 10 ms 5504 KB Output is correct
31 Correct 9 ms 5504 KB Output is correct
32 Correct 11 ms 5632 KB Output is correct
33 Correct 13 ms 5632 KB Output is correct
34 Correct 186 ms 6144 KB Output is correct
35 Runtime error 162 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Correct 17 ms 5760 KB Output is correct
37 Correct 305 ms 6452 KB Output is correct
38 Runtime error 165 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Correct 16 ms 5760 KB Output is correct
40 Correct 419 ms 6648 KB Output is correct
41 Runtime error 173 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Correct 15 ms 5760 KB Output is correct
43 Correct 508 ms 6996 KB Output is correct
44 Runtime error 170 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Correct 18 ms 5888 KB Output is correct
46 Correct 673 ms 7252 KB Output is correct
47 Runtime error 161 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Correct 21 ms 5888 KB Output is correct
49 Correct 884 ms 7412 KB Output is correct
50 Runtime error 157 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Correct 21 ms 5888 KB Output is correct
52 Execution timed out 1081 ms 7680 KB Time limit exceeded
53 Runtime error 170 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Correct 25 ms 6016 KB Output is correct
55 Execution timed out 1060 ms 7936 KB Time limit exceeded
56 Runtime error 180 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Correct 30 ms 6016 KB Output is correct
58 Execution timed out 1083 ms 8360 KB Time limit exceeded
59 Runtime error 183 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Correct 32 ms 6016 KB Output is correct
61 Execution timed out 1074 ms 8604 KB Time limit exceeded
62 Runtime error 166 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Incorrect 42 ms 6020 KB Output isn't correct
64 Incorrect 272 ms 6136 KB Output isn't correct
65 Incorrect 279 ms 6012 KB Output isn't correct
66 Incorrect 44 ms 6008 KB Output isn't correct
67 Correct 56 ms 6136 KB Output is correct
68 Incorrect 36 ms 6108 KB Output isn't correct
69 Incorrect 34 ms 6136 KB Output isn't correct
70 Incorrect 32 ms 6108 KB Output isn't correct
71 Incorrect 35 ms 6008 KB Output isn't correct
72 Incorrect 39 ms 6000 KB Output isn't correct
73 Incorrect 284 ms 6612 KB Output isn't correct
74 Runtime error 259 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Incorrect 705 ms 6648 KB Output isn't correct
76 Incorrect 549 ms 6696 KB Output isn't correct
77 Execution timed out 1071 ms 8392 KB Time limit exceeded
78 Correct 147 ms 7036 KB Output is correct
79 Runtime error 214 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Incorrect 773 ms 7144 KB Output isn't correct
81 Incorrect 606 ms 6620 KB Output isn't correct
82 Execution timed out 1069 ms 9976 KB Time limit exceeded
83 Incorrect 146 ms 6904 KB Output isn't correct
84 Runtime error 203 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Execution timed out 1063 ms 9368 KB Time limit exceeded
86 Execution timed out 1059 ms 7516 KB Time limit exceeded
87 Execution timed out 1032 ms 15484 KB Time limit exceeded
88 Incorrect 327 ms 9592 KB Output isn't correct
89 Runtime error 188 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Execution timed out 1069 ms 17416 KB Time limit exceeded
91 Execution timed out 1070 ms 38720 KB Time limit exceeded
92 Execution timed out 1070 ms 11772 KB Time limit exceeded