# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53608 |
2018-06-30T12:39:13 Z |
Diuven |
Mecho (IOI09_mecho) |
C++11 |
|
299 ms |
6616 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=810, inf=2e9;
int n, s;
char B[MX][MX];
int xs, ys, xl, yl;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int Y[MX][MX];
bool valid(int x, int y){
return 1<=x && x<=n && 1<=y && y<=n && (B[x][y]=='G' || B[x][y]=='H');
}
void bees(){
queue<pii> Q;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++){
if(B[i][j]=='H') Y[i][j]=0, Q.push({i,j});
else Y[i][j]=-1;
}
while(!Q.empty()){
pii p=Q.front(); Q.pop();
int x,y; tie(x,y)=p;
for(int k=0; k<4; k++){
int u=x+dx[k], v=y+dy[k];
if(!valid(u,v) || Y[u][v]>=0) continue;
Y[u][v]=Y[x][y]+s;
Q.push({u,v});
}
}
}
int D[MX][MX];
bool solve(int t){
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
D[i][j]=-1;
queue<pii> Q;
D[xs][ys]=0;
Q.push({xs,ys});
while(!Q.empty()){
int x,y; tie(x,y)=Q.front(); Q.pop();
for(int k=0; k<4; k++){
int u=x+dx[k], v=y+dy[k];
if(B[u][v]=='D') return true;
if(!valid(u,v) || D[u][v]>=0) continue;
int now=t*s+D[x][y]+1;
if(Y[u][v]>=0 && now>=Y[u][v]) continue;
D[u][v]=D[x][y]+1;
Q.push({u,v});
}
}
return false;
/*
cout<<"\nSOLVED "<<t<<'\n';
for(int i=1; i<=n; i++, cout<<'\n')
for(int j=1; j<=n; j++)
cout<<D[i][j]<<' ';
*/
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>s;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++){
cin>>B[i][j];
if(B[i][j]=='M') xs=i, ys=j, B[i][j]='G';
if(B[i][j]=='D') xl=i, yl=j;
}
bees();
int s=0, e=n*n;
while(s<e){
int m=(s+e+1)/2;
if(solve(m)) s=m;
else e=m-1;
}
cout<<(solve(s) ? s : -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
548 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
608 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
136 ms |
6220 KB |
Output is correct |
8 |
Correct |
2 ms |
6220 KB |
Output is correct |
9 |
Correct |
2 ms |
6220 KB |
Output is correct |
10 |
Correct |
2 ms |
6220 KB |
Output is correct |
11 |
Correct |
3 ms |
6220 KB |
Output is correct |
12 |
Incorrect |
3 ms |
6220 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
6220 KB |
Output isn't correct |
14 |
Correct |
3 ms |
6220 KB |
Output is correct |
15 |
Correct |
2 ms |
6220 KB |
Output is correct |
16 |
Correct |
2 ms |
6220 KB |
Output is correct |
17 |
Correct |
2 ms |
6220 KB |
Output is correct |
18 |
Correct |
2 ms |
6220 KB |
Output is correct |
19 |
Correct |
2 ms |
6220 KB |
Output is correct |
20 |
Correct |
2 ms |
6220 KB |
Output is correct |
21 |
Correct |
2 ms |
6220 KB |
Output is correct |
22 |
Correct |
3 ms |
6220 KB |
Output is correct |
23 |
Correct |
2 ms |
6220 KB |
Output is correct |
24 |
Correct |
3 ms |
6220 KB |
Output is correct |
25 |
Correct |
2 ms |
6220 KB |
Output is correct |
26 |
Correct |
2 ms |
6220 KB |
Output is correct |
27 |
Correct |
2 ms |
6220 KB |
Output is correct |
28 |
Correct |
2 ms |
6220 KB |
Output is correct |
29 |
Correct |
2 ms |
6220 KB |
Output is correct |
30 |
Correct |
3 ms |
6220 KB |
Output is correct |
31 |
Correct |
2 ms |
6220 KB |
Output is correct |
32 |
Correct |
3 ms |
6220 KB |
Output is correct |
33 |
Correct |
8 ms |
6220 KB |
Output is correct |
34 |
Correct |
8 ms |
6220 KB |
Output is correct |
35 |
Correct |
29 ms |
6220 KB |
Output is correct |
36 |
Correct |
10 ms |
6220 KB |
Output is correct |
37 |
Correct |
10 ms |
6220 KB |
Output is correct |
38 |
Correct |
39 ms |
6220 KB |
Output is correct |
39 |
Correct |
12 ms |
6220 KB |
Output is correct |
40 |
Correct |
12 ms |
6220 KB |
Output is correct |
41 |
Correct |
55 ms |
6220 KB |
Output is correct |
42 |
Correct |
14 ms |
6220 KB |
Output is correct |
43 |
Correct |
18 ms |
6220 KB |
Output is correct |
44 |
Correct |
74 ms |
6220 KB |
Output is correct |
45 |
Correct |
17 ms |
6220 KB |
Output is correct |
46 |
Correct |
17 ms |
6220 KB |
Output is correct |
47 |
Correct |
80 ms |
6220 KB |
Output is correct |
48 |
Correct |
18 ms |
6220 KB |
Output is correct |
49 |
Correct |
19 ms |
6220 KB |
Output is correct |
50 |
Correct |
98 ms |
6220 KB |
Output is correct |
51 |
Correct |
21 ms |
6220 KB |
Output is correct |
52 |
Correct |
21 ms |
6220 KB |
Output is correct |
53 |
Correct |
123 ms |
6220 KB |
Output is correct |
54 |
Correct |
23 ms |
6220 KB |
Output is correct |
55 |
Correct |
25 ms |
6220 KB |
Output is correct |
56 |
Correct |
146 ms |
6220 KB |
Output is correct |
57 |
Correct |
26 ms |
6220 KB |
Output is correct |
58 |
Correct |
27 ms |
6220 KB |
Output is correct |
59 |
Correct |
163 ms |
6220 KB |
Output is correct |
60 |
Correct |
29 ms |
6268 KB |
Output is correct |
61 |
Correct |
30 ms |
6268 KB |
Output is correct |
62 |
Correct |
184 ms |
6400 KB |
Output is correct |
63 |
Correct |
160 ms |
6400 KB |
Output is correct |
64 |
Correct |
299 ms |
6400 KB |
Output is correct |
65 |
Correct |
224 ms |
6400 KB |
Output is correct |
66 |
Correct |
186 ms |
6400 KB |
Output is correct |
67 |
Correct |
180 ms |
6420 KB |
Output is correct |
68 |
Correct |
77 ms |
6420 KB |
Output is correct |
69 |
Correct |
68 ms |
6420 KB |
Output is correct |
70 |
Correct |
69 ms |
6420 KB |
Output is correct |
71 |
Correct |
60 ms |
6420 KB |
Output is correct |
72 |
Incorrect |
48 ms |
6420 KB |
Output isn't correct |
73 |
Incorrect |
60 ms |
6420 KB |
Output isn't correct |
74 |
Correct |
85 ms |
6420 KB |
Output is correct |
75 |
Correct |
110 ms |
6608 KB |
Output is correct |
76 |
Correct |
100 ms |
6608 KB |
Output is correct |
77 |
Correct |
113 ms |
6608 KB |
Output is correct |
78 |
Correct |
114 ms |
6608 KB |
Output is correct |
79 |
Correct |
73 ms |
6608 KB |
Output is correct |
80 |
Correct |
92 ms |
6608 KB |
Output is correct |
81 |
Correct |
103 ms |
6608 KB |
Output is correct |
82 |
Correct |
88 ms |
6608 KB |
Output is correct |
83 |
Correct |
113 ms |
6608 KB |
Output is correct |
84 |
Correct |
106 ms |
6608 KB |
Output is correct |
85 |
Correct |
111 ms |
6608 KB |
Output is correct |
86 |
Correct |
120 ms |
6608 KB |
Output is correct |
87 |
Correct |
111 ms |
6608 KB |
Output is correct |
88 |
Correct |
119 ms |
6616 KB |
Output is correct |
89 |
Correct |
134 ms |
6616 KB |
Output is correct |
90 |
Correct |
134 ms |
6616 KB |
Output is correct |
91 |
Correct |
121 ms |
6616 KB |
Output is correct |
92 |
Correct |
121 ms |
6616 KB |
Output is correct |