# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
870701 |
2023-11-08T23:39:59 Z |
rsjw |
Mecho (IOI09_mecho) |
C++17 |
|
382 ms |
10164 KB |
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
const int N = 1010;
char a[N][N];
int n,m;
const int xp[]={1,-1,0,0};
const int yp[]={0,0,1,-1};
int dis1[N][N],dis2[N][N];
bool check(int limit) {
int i,j,k; queue<pii> q; pii u;
int nx,ny,x,y;
memset(dis1,0x3f,sizeof(dis1));
memset(dis2,0x3f,sizeof(dis2));
for(i=1;i<=n;i++) for(j=1;j<=n;j++) {
if(a[i][j]=='H') {
q.push(mp(i,j));
dis1[i][j]=0;
}
}
while(!q.empty()) {
u=q.front(); q.pop(); tie(x,y)=u;
for(k=0;k<4;k++) {
nx=x+xp[k],ny=y+yp[k];
if(1<=nx&&nx<=n&&1<=ny&&ny<=n&&dis1[nx][ny]>dis1[x][y]+1&&(a[nx][ny]=='G'||a[nx][ny]=='M')) {
dis1[nx][ny]=dis1[x][y]+1;
q.push(mp(nx,ny));
}
}
}
for(i=1;i<=n;i++) for(j=1;j<=n;j++) {
if(a[i][j]=='M') {
q.push(mp(i,j));
dis2[i][j]=0;
if(limit>=dis1[i][j]) return 0;
}
}
while(!q.empty()) {
u=q.front(); q.pop(); tie(x,y)=u;
for(k=0;k<4;k++) {
nx=x+xp[k],ny=y+yp[k];
if(1<=nx&&nx<=n&&1<=ny&&ny<=n&&dis2[nx][ny]>dis2[x][y]+1&&a[nx][ny]!='T') {
if((dis2[x][y]+1)/m+limit<dis1[nx][ny]) {
dis2[nx][ny]=dis2[x][y]+1;
q.push(mp(nx,ny));
}
}
}
}
for(i=1;i<=n;i++) for(j=1;j<=n;j++) {
if(a[i][j]=='D') {
if(dis2[i][j]!=0x3f3f3f3f) {
return 1;
}
}
}
return 0;
}
int main() {
int i,j;
cin>>n>>m;
for(i=1;i<=n;i++) cin>>(a[i]+1);
int l=0,r=1000005,mid;
while(l<=r) {
mid=(l+r)/2;
if(check(mid)) l=mid+1;
else r=mid-1;
} cout<<r<<endl;
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:62:11: warning: unused variable 'j' [-Wunused-variable]
62 | int i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8796 KB |
Output is correct |
2 |
Correct |
4 ms |
8796 KB |
Output is correct |
3 |
Correct |
4 ms |
8836 KB |
Output is correct |
4 |
Correct |
4 ms |
8832 KB |
Output is correct |
5 |
Correct |
4 ms |
8796 KB |
Output is correct |
6 |
Correct |
4 ms |
8796 KB |
Output is correct |
7 |
Correct |
285 ms |
9728 KB |
Output is correct |
8 |
Correct |
4 ms |
8796 KB |
Output is correct |
9 |
Correct |
4 ms |
8796 KB |
Output is correct |
10 |
Correct |
4 ms |
8796 KB |
Output is correct |
11 |
Correct |
4 ms |
8796 KB |
Output is correct |
12 |
Correct |
4 ms |
8796 KB |
Output is correct |
13 |
Correct |
5 ms |
8796 KB |
Output is correct |
14 |
Correct |
5 ms |
8796 KB |
Output is correct |
15 |
Correct |
4 ms |
8636 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
4 ms |
8796 KB |
Output is correct |
18 |
Correct |
4 ms |
8792 KB |
Output is correct |
19 |
Correct |
4 ms |
8792 KB |
Output is correct |
20 |
Correct |
4 ms |
8796 KB |
Output is correct |
21 |
Correct |
4 ms |
8796 KB |
Output is correct |
22 |
Correct |
4 ms |
8836 KB |
Output is correct |
23 |
Correct |
4 ms |
8792 KB |
Output is correct |
24 |
Correct |
4 ms |
8796 KB |
Output is correct |
25 |
Correct |
4 ms |
8792 KB |
Output is correct |
26 |
Correct |
4 ms |
8796 KB |
Output is correct |
27 |
Correct |
5 ms |
8832 KB |
Output is correct |
28 |
Correct |
5 ms |
9304 KB |
Output is correct |
29 |
Correct |
6 ms |
8648 KB |
Output is correct |
30 |
Correct |
5 ms |
8796 KB |
Output is correct |
31 |
Correct |
5 ms |
8796 KB |
Output is correct |
32 |
Correct |
5 ms |
8644 KB |
Output is correct |
33 |
Correct |
31 ms |
8796 KB |
Output is correct |
34 |
Correct |
28 ms |
9048 KB |
Output is correct |
35 |
Correct |
46 ms |
8796 KB |
Output is correct |
36 |
Correct |
37 ms |
8796 KB |
Output is correct |
37 |
Correct |
34 ms |
8792 KB |
Output is correct |
38 |
Correct |
61 ms |
8796 KB |
Output is correct |
39 |
Correct |
48 ms |
9052 KB |
Output is correct |
40 |
Correct |
44 ms |
9052 KB |
Output is correct |
41 |
Correct |
73 ms |
9052 KB |
Output is correct |
42 |
Correct |
65 ms |
9048 KB |
Output is correct |
43 |
Correct |
61 ms |
9256 KB |
Output is correct |
44 |
Correct |
93 ms |
9160 KB |
Output is correct |
45 |
Correct |
72 ms |
9048 KB |
Output is correct |
46 |
Correct |
62 ms |
9048 KB |
Output is correct |
47 |
Correct |
111 ms |
9052 KB |
Output is correct |
48 |
Correct |
84 ms |
9552 KB |
Output is correct |
49 |
Correct |
73 ms |
9308 KB |
Output is correct |
50 |
Correct |
138 ms |
9308 KB |
Output is correct |
51 |
Correct |
93 ms |
9304 KB |
Output is correct |
52 |
Correct |
85 ms |
9460 KB |
Output is correct |
53 |
Correct |
153 ms |
9304 KB |
Output is correct |
54 |
Correct |
124 ms |
9560 KB |
Output is correct |
55 |
Correct |
99 ms |
9560 KB |
Output is correct |
56 |
Correct |
193 ms |
9584 KB |
Output is correct |
57 |
Correct |
142 ms |
9656 KB |
Output is correct |
58 |
Correct |
112 ms |
9660 KB |
Output is correct |
59 |
Correct |
212 ms |
9660 KB |
Output is correct |
60 |
Correct |
142 ms |
9560 KB |
Output is correct |
61 |
Correct |
124 ms |
9564 KB |
Output is correct |
62 |
Correct |
232 ms |
9564 KB |
Output is correct |
63 |
Correct |
353 ms |
9712 KB |
Output is correct |
64 |
Correct |
373 ms |
9708 KB |
Output is correct |
65 |
Correct |
367 ms |
9712 KB |
Output is correct |
66 |
Correct |
382 ms |
9560 KB |
Output is correct |
67 |
Correct |
318 ms |
9564 KB |
Output is correct |
68 |
Correct |
329 ms |
9740 KB |
Output is correct |
69 |
Correct |
325 ms |
9564 KB |
Output is correct |
70 |
Correct |
328 ms |
9736 KB |
Output is correct |
71 |
Correct |
329 ms |
9740 KB |
Output is correct |
72 |
Correct |
310 ms |
9740 KB |
Output is correct |
73 |
Correct |
267 ms |
10068 KB |
Output is correct |
74 |
Correct |
267 ms |
9816 KB |
Output is correct |
75 |
Correct |
282 ms |
10068 KB |
Output is correct |
76 |
Correct |
269 ms |
9820 KB |
Output is correct |
77 |
Correct |
268 ms |
9820 KB |
Output is correct |
78 |
Correct |
271 ms |
9820 KB |
Output is correct |
79 |
Correct |
323 ms |
9816 KB |
Output is correct |
80 |
Correct |
296 ms |
10064 KB |
Output is correct |
81 |
Correct |
312 ms |
9960 KB |
Output is correct |
82 |
Correct |
267 ms |
9964 KB |
Output is correct |
83 |
Correct |
296 ms |
9816 KB |
Output is correct |
84 |
Correct |
284 ms |
9780 KB |
Output is correct |
85 |
Correct |
284 ms |
9796 KB |
Output is correct |
86 |
Correct |
293 ms |
9816 KB |
Output is correct |
87 |
Correct |
310 ms |
10164 KB |
Output is correct |
88 |
Correct |
288 ms |
9876 KB |
Output is correct |
89 |
Correct |
304 ms |
9872 KB |
Output is correct |
90 |
Correct |
298 ms |
9880 KB |
Output is correct |
91 |
Correct |
287 ms |
9876 KB |
Output is correct |
92 |
Correct |
287 ms |
10128 KB |
Output is correct |