Submission #58198

# Submission time Handle Problem Language Result Execution time Memory
58198 2018-07-17T06:29:06 Z gnoor Mecho (IOI09_mecho) C++17
19 / 100
256 ms 9772 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

struct cell {
	int r,c;
};

queue<cell> bee;
queue<cell> bear;
bool wall[1010][1010];

int disBear[1010][1010];
int disBee[1010][1010];
cell home;
cell start;

int di[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
int n,s;

bool check(int x) {
	memset(disBear,63,sizeof(disBear));
	disBear[start.r][start.c]=x*s;
	if (disBee[start.r][start.c]<=x*s) return false;
	bear.push(start);
	int nowr,nowc,nextr,nextc;
	while (!bear.empty()) {
		nowr=bear.front().r;
		nowc=bear.front().c;
		bear.pop();
		for (int i=0;i<4;i++) {
			nextr=nowr+di[i][0];
			nextc=nowc+di[i][1];
			if (nextc<0||nextc>=n||nextr<0||nextr>=n) continue;
			if (wall[nextr][nextc]) continue;
			if (disBear[nextr][nextc]<=disBear[nowr][nowc]+1) continue;
			if (disBee[nextr][nextc]<=(disBear[nowr][nowc]+1)/s) continue;
			disBear[nextr][nextc]=disBear[nowr][nowc]+1;
			bear.push(cell{nextr,nextc});
		}
	}

	return disBear[home.r][home.c]!=0x3f3f3f3f;
}

int main () {
	scanf("%d%d",&n,&s);
	char x;
	

	memset(disBee,63,sizeof(disBee));
	for (int i=0;i<n;i++) {
		for (int j=0;j<n;j++) {
			scanf(" %c",&x);
			if (x=='T') wall[i][j]=true;
			else if (x=='M'){
				start=cell{i,j};
			}
			else if (x=='D') home=cell{i,j};
			else if (x=='H') {
				bee.push(cell{i,j});
				disBee[i][j]=0;
			}
		}
	}


	int nowr,nowc;
	int nextr,nextc;
	while (!bee.empty()) {
		nowr=bee.front().r;
		nowc=bee.front().c;
		bee.pop();
		for (int i=0;i<4;i++) {
			nextr=nowr+di[i][0];
			nextc=nowc+di[i][1];
			if (nextc<0||nextc>=n||nextr<0||nextr>=n) continue;
			if (wall[nextr][nextc]) continue;
			if (nextr==home.r&&nextc==home.c) continue;
			if (disBee[nextr][nextc]<=disBee[nowr][nowc]+1) continue;
			disBee[nextr][nextc]=disBee[nowr][nowc]+1;
			bee.push(cell{nextr,nextc});
		}
	}

	int lo=0;
	int hi=2*n;
	int mid;	
	while (lo<hi) {
		mid=(lo+hi+1)>>1;
		if (check(mid)) {
			lo=mid;
		} else {
			hi=mid-1;
		}
	}

	if (check(lo)) printf("%d\n",lo);
	else printf("-1\n");

	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:51: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:58:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c",&x);
    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8312 KB Output is correct
2 Correct 10 ms 8372 KB Output is correct
3 Correct 10 ms 8372 KB Output is correct
4 Correct 9 ms 8372 KB Output is correct
5 Correct 12 ms 8376 KB Output is correct
6 Correct 12 ms 8416 KB Output is correct
7 Incorrect 134 ms 9180 KB Output isn't correct
8 Correct 11 ms 9180 KB Output is correct
9 Incorrect 9 ms 9180 KB Output isn't correct
10 Correct 9 ms 9180 KB Output is correct
11 Incorrect 10 ms 9180 KB Output isn't correct
12 Incorrect 10 ms 9180 KB Output isn't correct
13 Correct 10 ms 9180 KB Output is correct
14 Correct 11 ms 9180 KB Output is correct
15 Incorrect 12 ms 9180 KB Output isn't correct
16 Incorrect 11 ms 9180 KB Output isn't correct
17 Incorrect 9 ms 9180 KB Output isn't correct
18 Incorrect 11 ms 9180 KB Output isn't correct
19 Incorrect 12 ms 9180 KB Output isn't correct
20 Incorrect 10 ms 9180 KB Output isn't correct
21 Incorrect 10 ms 9180 KB Output isn't correct
22 Incorrect 11 ms 9180 KB Output isn't correct
23 Incorrect 13 ms 9180 KB Output isn't correct
24 Incorrect 13 ms 9180 KB Output isn't correct
25 Incorrect 10 ms 9180 KB Output isn't correct
26 Incorrect 11 ms 9180 KB Output isn't correct
27 Incorrect 12 ms 9180 KB Output isn't correct
28 Incorrect 13 ms 9180 KB Output isn't correct
29 Incorrect 11 ms 9180 KB Output isn't correct
30 Incorrect 14 ms 9180 KB Output isn't correct
31 Incorrect 11 ms 9180 KB Output isn't correct
32 Incorrect 10 ms 9180 KB Output isn't correct
33 Incorrect 30 ms 9180 KB Output isn't correct
34 Incorrect 36 ms 9180 KB Output isn't correct
35 Incorrect 25 ms 9180 KB Output isn't correct
36 Incorrect 46 ms 9180 KB Output isn't correct
37 Incorrect 48 ms 9180 KB Output isn't correct
38 Incorrect 29 ms 9180 KB Output isn't correct
39 Incorrect 47 ms 9180 KB Output isn't correct
40 Incorrect 45 ms 9180 KB Output isn't correct
41 Incorrect 47 ms 9180 KB Output isn't correct
42 Incorrect 69 ms 9180 KB Output isn't correct
43 Incorrect 108 ms 9180 KB Output isn't correct
44 Incorrect 41 ms 9180 KB Output isn't correct
45 Incorrect 73 ms 9180 KB Output isn't correct
46 Incorrect 69 ms 9180 KB Output isn't correct
47 Incorrect 68 ms 9180 KB Output isn't correct
48 Incorrect 76 ms 9188 KB Output isn't correct
49 Incorrect 135 ms 9188 KB Output isn't correct
50 Incorrect 61 ms 9188 KB Output isn't correct
51 Incorrect 95 ms 9240 KB Output isn't correct
52 Incorrect 130 ms 9340 KB Output isn't correct
53 Incorrect 69 ms 9340 KB Output isn't correct
54 Incorrect 89 ms 9340 KB Output isn't correct
55 Incorrect 112 ms 9340 KB Output isn't correct
56 Incorrect 105 ms 9340 KB Output isn't correct
57 Incorrect 120 ms 9340 KB Output isn't correct
58 Incorrect 148 ms 9424 KB Output isn't correct
59 Incorrect 76 ms 9424 KB Output isn't correct
60 Incorrect 124 ms 9460 KB Output isn't correct
61 Incorrect 141 ms 9460 KB Output isn't correct
62 Incorrect 118 ms 9460 KB Output isn't correct
63 Correct 225 ms 9468 KB Output is correct
64 Incorrect 168 ms 9488 KB Output isn't correct
65 Correct 256 ms 9488 KB Output is correct
66 Correct 236 ms 9488 KB Output is correct
67 Correct 244 ms 9488 KB Output is correct
68 Correct 95 ms 9488 KB Output is correct
69 Incorrect 99 ms 9488 KB Output isn't correct
70 Correct 111 ms 9488 KB Output is correct
71 Correct 106 ms 9488 KB Output is correct
72 Incorrect 113 ms 9488 KB Output isn't correct
73 Incorrect 95 ms 9724 KB Output isn't correct
74 Incorrect 116 ms 9724 KB Output isn't correct
75 Incorrect 165 ms 9724 KB Output isn't correct
76 Incorrect 141 ms 9724 KB Output isn't correct
77 Incorrect 160 ms 9724 KB Output isn't correct
78 Correct 158 ms 9724 KB Output is correct
79 Incorrect 92 ms 9724 KB Output isn't correct
80 Incorrect 99 ms 9724 KB Output isn't correct
81 Correct 128 ms 9772 KB Output is correct
82 Incorrect 150 ms 9772 KB Output isn't correct
83 Correct 185 ms 9772 KB Output is correct
84 Incorrect 111 ms 9772 KB Output isn't correct
85 Incorrect 133 ms 9772 KB Output isn't correct
86 Correct 159 ms 9772 KB Output is correct
87 Incorrect 137 ms 9772 KB Output isn't correct
88 Correct 162 ms 9772 KB Output is correct
89 Incorrect 169 ms 9772 KB Output isn't correct
90 Incorrect 106 ms 9772 KB Output isn't correct
91 Incorrect 139 ms 9772 KB Output isn't correct
92 Correct 140 ms 9772 KB Output is correct