# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58195 |
2018-07-17T06:26:31 Z |
gnoor |
Mecho (IOI09_mecho) |
C++17 |
|
353 ms |
9648 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;
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:50: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:57: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 |
11 ms |
8312 KB |
Output is correct |
2 |
Correct |
10 ms |
8312 KB |
Output is correct |
3 |
Correct |
10 ms |
8372 KB |
Output is correct |
4 |
Correct |
11 ms |
8372 KB |
Output is correct |
5 |
Correct |
11 ms |
8408 KB |
Output is correct |
6 |
Correct |
11 ms |
8480 KB |
Output is correct |
7 |
Correct |
238 ms |
9376 KB |
Output is correct |
8 |
Correct |
11 ms |
9376 KB |
Output is correct |
9 |
Correct |
11 ms |
9376 KB |
Output is correct |
10 |
Correct |
11 ms |
9376 KB |
Output is correct |
11 |
Correct |
11 ms |
9376 KB |
Output is correct |
12 |
Incorrect |
12 ms |
9376 KB |
Output isn't correct |
13 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
14 |
Correct |
10 ms |
9376 KB |
Output is correct |
15 |
Incorrect |
12 ms |
9376 KB |
Output isn't correct |
16 |
Incorrect |
11 ms |
9376 KB |
Output isn't correct |
17 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
9376 KB |
Output isn't correct |
19 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
20 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
21 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
22 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
23 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
24 |
Incorrect |
12 ms |
9376 KB |
Output isn't correct |
25 |
Incorrect |
12 ms |
9376 KB |
Output isn't correct |
26 |
Incorrect |
12 ms |
9376 KB |
Output isn't correct |
27 |
Incorrect |
11 ms |
9376 KB |
Output isn't correct |
28 |
Incorrect |
13 ms |
9376 KB |
Output isn't correct |
29 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
30 |
Incorrect |
13 ms |
9376 KB |
Output isn't correct |
31 |
Incorrect |
10 ms |
9376 KB |
Output isn't correct |
32 |
Incorrect |
11 ms |
9376 KB |
Output isn't correct |
33 |
Incorrect |
37 ms |
9376 KB |
Output isn't correct |
34 |
Incorrect |
52 ms |
9376 KB |
Output isn't correct |
35 |
Correct |
69 ms |
9376 KB |
Output is correct |
36 |
Incorrect |
35 ms |
9376 KB |
Output isn't correct |
37 |
Incorrect |
85 ms |
9376 KB |
Output isn't correct |
38 |
Correct |
70 ms |
9376 KB |
Output is correct |
39 |
Incorrect |
43 ms |
9376 KB |
Output isn't correct |
40 |
Incorrect |
84 ms |
9376 KB |
Output isn't correct |
41 |
Correct |
83 ms |
9376 KB |
Output is correct |
42 |
Incorrect |
50 ms |
9376 KB |
Output isn't correct |
43 |
Incorrect |
65 ms |
9376 KB |
Output isn't correct |
44 |
Correct |
107 ms |
9376 KB |
Output is correct |
45 |
Incorrect |
61 ms |
9376 KB |
Output isn't correct |
46 |
Incorrect |
125 ms |
9376 KB |
Output isn't correct |
47 |
Correct |
113 ms |
9376 KB |
Output is correct |
48 |
Incorrect |
69 ms |
9376 KB |
Output isn't correct |
49 |
Incorrect |
186 ms |
9376 KB |
Output isn't correct |
50 |
Correct |
176 ms |
9376 KB |
Output is correct |
51 |
Incorrect |
109 ms |
9376 KB |
Output isn't correct |
52 |
Incorrect |
152 ms |
9376 KB |
Output isn't correct |
53 |
Correct |
219 ms |
9376 KB |
Output is correct |
54 |
Incorrect |
94 ms |
9376 KB |
Output isn't correct |
55 |
Incorrect |
180 ms |
9376 KB |
Output isn't correct |
56 |
Correct |
237 ms |
9376 KB |
Output is correct |
57 |
Incorrect |
98 ms |
9376 KB |
Output isn't correct |
58 |
Incorrect |
203 ms |
9376 KB |
Output isn't correct |
59 |
Correct |
268 ms |
9376 KB |
Output is correct |
60 |
Incorrect |
125 ms |
9464 KB |
Output isn't correct |
61 |
Incorrect |
224 ms |
9468 KB |
Output isn't correct |
62 |
Correct |
353 ms |
9468 KB |
Output is correct |
63 |
Correct |
201 ms |
9468 KB |
Output is correct |
64 |
Correct |
317 ms |
9468 KB |
Output is correct |
65 |
Correct |
302 ms |
9468 KB |
Output is correct |
66 |
Correct |
280 ms |
9468 KB |
Output is correct |
67 |
Correct |
261 ms |
9468 KB |
Output is correct |
68 |
Correct |
113 ms |
9468 KB |
Output is correct |
69 |
Correct |
124 ms |
9468 KB |
Output is correct |
70 |
Correct |
94 ms |
9468 KB |
Output is correct |
71 |
Correct |
145 ms |
9468 KB |
Output is correct |
72 |
Incorrect |
80 ms |
9468 KB |
Output isn't correct |
73 |
Incorrect |
144 ms |
9572 KB |
Output isn't correct |
74 |
Correct |
149 ms |
9648 KB |
Output is correct |
75 |
Correct |
159 ms |
9648 KB |
Output is correct |
76 |
Correct |
168 ms |
9648 KB |
Output is correct |
77 |
Correct |
159 ms |
9648 KB |
Output is correct |
78 |
Correct |
177 ms |
9648 KB |
Output is correct |
79 |
Correct |
132 ms |
9648 KB |
Output is correct |
80 |
Correct |
146 ms |
9648 KB |
Output is correct |
81 |
Correct |
180 ms |
9648 KB |
Output is correct |
82 |
Correct |
158 ms |
9648 KB |
Output is correct |
83 |
Correct |
218 ms |
9648 KB |
Output is correct |
84 |
Correct |
173 ms |
9648 KB |
Output is correct |
85 |
Correct |
189 ms |
9648 KB |
Output is correct |
86 |
Correct |
186 ms |
9648 KB |
Output is correct |
87 |
Correct |
163 ms |
9648 KB |
Output is correct |
88 |
Correct |
215 ms |
9648 KB |
Output is correct |
89 |
Correct |
223 ms |
9648 KB |
Output is correct |
90 |
Correct |
272 ms |
9648 KB |
Output is correct |
91 |
Correct |
182 ms |
9648 KB |
Output is correct |
92 |
Correct |
186 ms |
9648 KB |
Output is correct |