# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53609 |
2018-06-30T12:44:01 Z |
Diuven |
Mecho (IOI09_mecho) |
C++11 |
|
269 ms |
6620 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]=t*s;
if(D[xs][ys]>=Y[xs][ys]) return false;
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;
}
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 |
Incorrect |
3 ms |
380 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
432 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
480 KB |
Output isn't correct |
5 |
Correct |
2 ms |
612 KB |
Output is correct |
6 |
Incorrect |
3 ms |
612 KB |
Output isn't correct |
7 |
Incorrect |
157 ms |
6460 KB |
Output isn't correct |
8 |
Correct |
2 ms |
6460 KB |
Output is correct |
9 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
12 |
Correct |
3 ms |
6460 KB |
Output is correct |
13 |
Correct |
3 ms |
6460 KB |
Output is correct |
14 |
Correct |
3 ms |
6460 KB |
Output is correct |
15 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
19 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
21 |
Incorrect |
4 ms |
6460 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
23 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
24 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
26 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
29 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
30 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
31 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
33 |
Incorrect |
10 ms |
6460 KB |
Output isn't correct |
34 |
Incorrect |
8 ms |
6460 KB |
Output isn't correct |
35 |
Incorrect |
28 ms |
6460 KB |
Output isn't correct |
36 |
Incorrect |
10 ms |
6460 KB |
Output isn't correct |
37 |
Incorrect |
10 ms |
6460 KB |
Output isn't correct |
38 |
Incorrect |
34 ms |
6460 KB |
Output isn't correct |
39 |
Incorrect |
12 ms |
6460 KB |
Output isn't correct |
40 |
Incorrect |
12 ms |
6460 KB |
Output isn't correct |
41 |
Incorrect |
46 ms |
6460 KB |
Output isn't correct |
42 |
Incorrect |
21 ms |
6460 KB |
Output isn't correct |
43 |
Incorrect |
14 ms |
6460 KB |
Output isn't correct |
44 |
Incorrect |
71 ms |
6460 KB |
Output isn't correct |
45 |
Incorrect |
18 ms |
6460 KB |
Output isn't correct |
46 |
Incorrect |
17 ms |
6460 KB |
Output isn't correct |
47 |
Incorrect |
76 ms |
6460 KB |
Output isn't correct |
48 |
Incorrect |
21 ms |
6460 KB |
Output isn't correct |
49 |
Incorrect |
21 ms |
6460 KB |
Output isn't correct |
50 |
Incorrect |
110 ms |
6460 KB |
Output isn't correct |
51 |
Incorrect |
23 ms |
6460 KB |
Output isn't correct |
52 |
Incorrect |
23 ms |
6460 KB |
Output isn't correct |
53 |
Incorrect |
118 ms |
6460 KB |
Output isn't correct |
54 |
Incorrect |
26 ms |
6460 KB |
Output isn't correct |
55 |
Incorrect |
25 ms |
6460 KB |
Output isn't correct |
56 |
Incorrect |
139 ms |
6460 KB |
Output isn't correct |
57 |
Incorrect |
33 ms |
6460 KB |
Output isn't correct |
58 |
Incorrect |
35 ms |
6460 KB |
Output isn't correct |
59 |
Incorrect |
181 ms |
6460 KB |
Output isn't correct |
60 |
Incorrect |
35 ms |
6460 KB |
Output isn't correct |
61 |
Incorrect |
32 ms |
6460 KB |
Output isn't correct |
62 |
Incorrect |
198 ms |
6460 KB |
Output isn't correct |
63 |
Correct |
135 ms |
6460 KB |
Output is correct |
64 |
Incorrect |
269 ms |
6460 KB |
Output isn't correct |
65 |
Incorrect |
194 ms |
6468 KB |
Output isn't correct |
66 |
Incorrect |
162 ms |
6468 KB |
Output isn't correct |
67 |
Correct |
162 ms |
6468 KB |
Output is correct |
68 |
Correct |
76 ms |
6468 KB |
Output is correct |
69 |
Incorrect |
86 ms |
6468 KB |
Output isn't correct |
70 |
Incorrect |
62 ms |
6468 KB |
Output isn't correct |
71 |
Incorrect |
58 ms |
6468 KB |
Output isn't correct |
72 |
Incorrect |
47 ms |
6520 KB |
Output isn't correct |
73 |
Correct |
66 ms |
6520 KB |
Output is correct |
74 |
Incorrect |
97 ms |
6520 KB |
Output isn't correct |
75 |
Incorrect |
108 ms |
6520 KB |
Output isn't correct |
76 |
Incorrect |
97 ms |
6520 KB |
Output isn't correct |
77 |
Incorrect |
114 ms |
6520 KB |
Output isn't correct |
78 |
Correct |
122 ms |
6520 KB |
Output is correct |
79 |
Incorrect |
73 ms |
6520 KB |
Output isn't correct |
80 |
Incorrect |
87 ms |
6520 KB |
Output isn't correct |
81 |
Incorrect |
136 ms |
6520 KB |
Output isn't correct |
82 |
Incorrect |
103 ms |
6520 KB |
Output isn't correct |
83 |
Correct |
109 ms |
6520 KB |
Output is correct |
84 |
Incorrect |
99 ms |
6520 KB |
Output isn't correct |
85 |
Incorrect |
112 ms |
6572 KB |
Output isn't correct |
86 |
Incorrect |
116 ms |
6572 KB |
Output isn't correct |
87 |
Incorrect |
109 ms |
6572 KB |
Output isn't correct |
88 |
Correct |
158 ms |
6620 KB |
Output is correct |
89 |
Incorrect |
184 ms |
6620 KB |
Output isn't correct |
90 |
Incorrect |
169 ms |
6620 KB |
Output isn't correct |
91 |
Incorrect |
160 ms |
6620 KB |
Output isn't correct |
92 |
Incorrect |
132 ms |
6620 KB |
Output isn't correct |