# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60054 |
2018-07-23T14:13:25 Z |
nvmdava |
Mecho (IOI09_mecho) |
C++17 |
|
536 ms |
6528 KB |
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
using namespace std;
int n,s;
int t[802][802];
char c[802][802];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int chk[802][802];
queue<pair<int, int > > q;
bool pos(int x,int y, int now){
memset(chk,0,sizeof(chk));
if(now >= t[x][y]){
return 0;
}
chk[x][y] = now;
q.push(mp(x,y));
while(!q.empty()){
x = q.front().ff;
y = q.front().ss;
q.pop();
for(int i = 0; i < 4; i++){
if(c[x + dx[i]][y + dy[i]]=='D'){
while(!q.empty()){
q.pop();
}
return 1;
}
if(chk[x + dx[i]][y + dy[i]]==0 && t[x + dx[i]][y + dy[i]] > chk[x][y] + 1){
chk[x + dx[i]][y + dy[i]] = chk[x][y] + 1;
q.push( mp(x + dx[i] , y + dy[i]) );
}
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i,j,xx,yy;
cin>>n>>s;
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
cin>>c[i][j];
if(c[i][j]=='H'){
q.push(mp(i,j));
} else if(c[i][j]=='M'){
xx=i;
yy=j;
}
}
}
int x,y;
while(!q.empty()){
x=q.front().ff;
y=q.front().ss;
q.pop();
for(i=0;i<4;i++){
if((c[x + dx[i]][y + dy[i]]=='G'||c[x + dx[i]][y + dy[i]]=='M')&&t[x + dx[i]][y + dy[i]]==0){
t[x + dx[i]][y + dy[i]] = t[x][y]+s;
q.push(mp(x + dx[i] , y + dy[i]));
}
}
}
int l = 0 , r = 1e9,m;
if(pos(xx,yy,0)==0){
cout<<-1;
return 0;
}
while(l + 1 != r){
m = (l + r) / 2;
if(pos(xx,yy,m)){
l = m;
} else {
r = m;
}
}
cout<<l/s;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:71:8: warning: 'yy' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(pos(xx,yy,0)==0){
~~~^~~~~~~~~
mecho.cpp:71:8: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2936 KB |
Output is correct |
2 |
Correct |
10 ms |
3048 KB |
Output is correct |
3 |
Correct |
8 ms |
3048 KB |
Output is correct |
4 |
Correct |
10 ms |
3048 KB |
Output is correct |
5 |
Correct |
11 ms |
3048 KB |
Output is correct |
6 |
Correct |
9 ms |
3052 KB |
Output is correct |
7 |
Correct |
248 ms |
6428 KB |
Output is correct |
8 |
Correct |
5 ms |
6428 KB |
Output is correct |
9 |
Correct |
10 ms |
6428 KB |
Output is correct |
10 |
Correct |
9 ms |
6428 KB |
Output is correct |
11 |
Correct |
9 ms |
6428 KB |
Output is correct |
12 |
Correct |
10 ms |
6428 KB |
Output is correct |
13 |
Correct |
10 ms |
6428 KB |
Output is correct |
14 |
Correct |
6 ms |
6428 KB |
Output is correct |
15 |
Correct |
10 ms |
6428 KB |
Output is correct |
16 |
Correct |
9 ms |
6428 KB |
Output is correct |
17 |
Correct |
9 ms |
6428 KB |
Output is correct |
18 |
Correct |
10 ms |
6428 KB |
Output is correct |
19 |
Correct |
9 ms |
6428 KB |
Output is correct |
20 |
Correct |
10 ms |
6428 KB |
Output is correct |
21 |
Correct |
11 ms |
6428 KB |
Output is correct |
22 |
Correct |
12 ms |
6428 KB |
Output is correct |
23 |
Correct |
10 ms |
6428 KB |
Output is correct |
24 |
Correct |
11 ms |
6428 KB |
Output is correct |
25 |
Correct |
10 ms |
6428 KB |
Output is correct |
26 |
Correct |
10 ms |
6428 KB |
Output is correct |
27 |
Correct |
9 ms |
6428 KB |
Output is correct |
28 |
Correct |
11 ms |
6428 KB |
Output is correct |
29 |
Correct |
10 ms |
6428 KB |
Output is correct |
30 |
Correct |
9 ms |
6428 KB |
Output is correct |
31 |
Correct |
10 ms |
6428 KB |
Output is correct |
32 |
Correct |
11 ms |
6428 KB |
Output is correct |
33 |
Correct |
14 ms |
6428 KB |
Output is correct |
34 |
Correct |
14 ms |
6428 KB |
Output is correct |
35 |
Correct |
87 ms |
6428 KB |
Output is correct |
36 |
Correct |
15 ms |
6428 KB |
Output is correct |
37 |
Correct |
16 ms |
6428 KB |
Output is correct |
38 |
Correct |
87 ms |
6428 KB |
Output is correct |
39 |
Correct |
19 ms |
6428 KB |
Output is correct |
40 |
Correct |
23 ms |
6428 KB |
Output is correct |
41 |
Correct |
148 ms |
6428 KB |
Output is correct |
42 |
Correct |
18 ms |
6428 KB |
Output is correct |
43 |
Correct |
21 ms |
6428 KB |
Output is correct |
44 |
Correct |
171 ms |
6428 KB |
Output is correct |
45 |
Correct |
19 ms |
6428 KB |
Output is correct |
46 |
Correct |
19 ms |
6428 KB |
Output is correct |
47 |
Correct |
177 ms |
6428 KB |
Output is correct |
48 |
Correct |
24 ms |
6428 KB |
Output is correct |
49 |
Correct |
22 ms |
6428 KB |
Output is correct |
50 |
Correct |
300 ms |
6428 KB |
Output is correct |
51 |
Correct |
28 ms |
6428 KB |
Output is correct |
52 |
Correct |
29 ms |
6428 KB |
Output is correct |
53 |
Correct |
308 ms |
6428 KB |
Output is correct |
54 |
Correct |
29 ms |
6428 KB |
Output is correct |
55 |
Correct |
29 ms |
6428 KB |
Output is correct |
56 |
Correct |
316 ms |
6428 KB |
Output is correct |
57 |
Correct |
33 ms |
6428 KB |
Output is correct |
58 |
Correct |
27 ms |
6428 KB |
Output is correct |
59 |
Correct |
341 ms |
6428 KB |
Output is correct |
60 |
Correct |
31 ms |
6428 KB |
Output is correct |
61 |
Correct |
38 ms |
6428 KB |
Output is correct |
62 |
Correct |
441 ms |
6428 KB |
Output is correct |
63 |
Correct |
160 ms |
6428 KB |
Output is correct |
64 |
Correct |
536 ms |
6428 KB |
Output is correct |
65 |
Correct |
357 ms |
6428 KB |
Output is correct |
66 |
Correct |
247 ms |
6428 KB |
Output is correct |
67 |
Correct |
56 ms |
6428 KB |
Output is correct |
68 |
Correct |
123 ms |
6428 KB |
Output is correct |
69 |
Correct |
100 ms |
6428 KB |
Output is correct |
70 |
Correct |
69 ms |
6428 KB |
Output is correct |
71 |
Correct |
76 ms |
6428 KB |
Output is correct |
72 |
Correct |
60 ms |
6428 KB |
Output is correct |
73 |
Correct |
86 ms |
6524 KB |
Output is correct |
74 |
Correct |
180 ms |
6524 KB |
Output is correct |
75 |
Correct |
138 ms |
6524 KB |
Output is correct |
76 |
Correct |
153 ms |
6524 KB |
Output is correct |
77 |
Correct |
149 ms |
6524 KB |
Output is correct |
78 |
Correct |
57 ms |
6524 KB |
Output is correct |
79 |
Correct |
172 ms |
6528 KB |
Output is correct |
80 |
Correct |
131 ms |
6528 KB |
Output is correct |
81 |
Correct |
176 ms |
6528 KB |
Output is correct |
82 |
Correct |
152 ms |
6528 KB |
Output is correct |
83 |
Correct |
174 ms |
6528 KB |
Output is correct |
84 |
Correct |
236 ms |
6528 KB |
Output is correct |
85 |
Correct |
210 ms |
6528 KB |
Output is correct |
86 |
Correct |
208 ms |
6528 KB |
Output is correct |
87 |
Correct |
182 ms |
6528 KB |
Output is correct |
88 |
Correct |
234 ms |
6528 KB |
Output is correct |
89 |
Correct |
306 ms |
6528 KB |
Output is correct |
90 |
Correct |
224 ms |
6528 KB |
Output is correct |
91 |
Correct |
275 ms |
6528 KB |
Output is correct |
92 |
Correct |
189 ms |
6528 KB |
Output is correct |