# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53563 |
2018-06-30T08:19:52 Z |
노영훈(#1418) |
Mecho (IOI09_mecho) |
C++11 |
|
228 ms |
6528 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]+1;
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(!valid(u,v) || D[u][v]>=0) continue;
int now=t+(D[x][y]+1)/s;
if(Y[u][v]>=0 && now>=Y[u][v]) continue;
D[u][v]=D[x][y]+1;
Q.push({u,v});
}
}
/*
cout<<"\nSOLVED "<<t<<'\n';
for(int i=1; i<=n; i++, cout<<'\n')
for(int j=1; j<=n; j++)
cout<<D[i][j]<<' ';
*/
return D[xl][yl]>=0;
}
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, B[i][j]='G';
}
bees();
int s=0, e=2*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 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Incorrect |
2 ms |
560 KB |
Output isn't correct |
5 |
Correct |
2 ms |
560 KB |
Output is correct |
6 |
Incorrect |
2 ms |
672 KB |
Output isn't correct |
7 |
Incorrect |
118 ms |
6460 KB |
Output isn't correct |
8 |
Correct |
1 ms |
6460 KB |
Output is correct |
9 |
Correct |
2 ms |
6460 KB |
Output is correct |
10 |
Correct |
2 ms |
6460 KB |
Output is correct |
11 |
Correct |
2 ms |
6460 KB |
Output is correct |
12 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
14 |
Correct |
3 ms |
6460 KB |
Output is correct |
15 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
21 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
24 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
6460 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
6460 KB |
Output isn't correct |
28 |
Incorrect |
3 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 |
3 ms |
6460 KB |
Output isn't correct |
33 |
Incorrect |
16 ms |
6460 KB |
Output isn't correct |
34 |
Incorrect |
23 ms |
6460 KB |
Output isn't correct |
35 |
Correct |
29 ms |
6460 KB |
Output is correct |
36 |
Incorrect |
21 ms |
6460 KB |
Output isn't correct |
37 |
Incorrect |
33 ms |
6460 KB |
Output isn't correct |
38 |
Correct |
37 ms |
6460 KB |
Output is correct |
39 |
Incorrect |
30 ms |
6460 KB |
Output isn't correct |
40 |
Incorrect |
40 ms |
6460 KB |
Output isn't correct |
41 |
Correct |
48 ms |
6460 KB |
Output is correct |
42 |
Incorrect |
31 ms |
6460 KB |
Output isn't correct |
43 |
Incorrect |
45 ms |
6460 KB |
Output isn't correct |
44 |
Correct |
68 ms |
6460 KB |
Output is correct |
45 |
Incorrect |
57 ms |
6460 KB |
Output isn't correct |
46 |
Incorrect |
59 ms |
6460 KB |
Output isn't correct |
47 |
Correct |
74 ms |
6460 KB |
Output is correct |
48 |
Incorrect |
49 ms |
6460 KB |
Output isn't correct |
49 |
Incorrect |
67 ms |
6460 KB |
Output isn't correct |
50 |
Correct |
93 ms |
6460 KB |
Output is correct |
51 |
Incorrect |
57 ms |
6460 KB |
Output isn't correct |
52 |
Incorrect |
81 ms |
6460 KB |
Output isn't correct |
53 |
Correct |
124 ms |
6460 KB |
Output is correct |
54 |
Incorrect |
65 ms |
6460 KB |
Output isn't correct |
55 |
Incorrect |
88 ms |
6460 KB |
Output isn't correct |
56 |
Correct |
166 ms |
6460 KB |
Output is correct |
57 |
Incorrect |
70 ms |
6460 KB |
Output isn't correct |
58 |
Incorrect |
109 ms |
6460 KB |
Output isn't correct |
59 |
Correct |
198 ms |
6460 KB |
Output is correct |
60 |
Incorrect |
83 ms |
6460 KB |
Output isn't correct |
61 |
Incorrect |
124 ms |
6460 KB |
Output isn't correct |
62 |
Correct |
197 ms |
6460 KB |
Output is correct |
63 |
Correct |
127 ms |
6460 KB |
Output is correct |
64 |
Correct |
201 ms |
6460 KB |
Output is correct |
65 |
Correct |
228 ms |
6460 KB |
Output is correct |
66 |
Correct |
209 ms |
6460 KB |
Output is correct |
67 |
Correct |
178 ms |
6460 KB |
Output is correct |
68 |
Correct |
97 ms |
6460 KB |
Output is correct |
69 |
Correct |
68 ms |
6460 KB |
Output is correct |
70 |
Correct |
66 ms |
6472 KB |
Output is correct |
71 |
Correct |
55 ms |
6472 KB |
Output is correct |
72 |
Incorrect |
46 ms |
6472 KB |
Output isn't correct |
73 |
Incorrect |
84 ms |
6488 KB |
Output isn't correct |
74 |
Correct |
94 ms |
6488 KB |
Output is correct |
75 |
Correct |
124 ms |
6496 KB |
Output is correct |
76 |
Correct |
132 ms |
6496 KB |
Output is correct |
77 |
Correct |
132 ms |
6496 KB |
Output is correct |
78 |
Correct |
133 ms |
6496 KB |
Output is correct |
79 |
Correct |
85 ms |
6496 KB |
Output is correct |
80 |
Correct |
98 ms |
6528 KB |
Output is correct |
81 |
Correct |
112 ms |
6528 KB |
Output is correct |
82 |
Correct |
90 ms |
6528 KB |
Output is correct |
83 |
Correct |
117 ms |
6528 KB |
Output is correct |
84 |
Correct |
113 ms |
6528 KB |
Output is correct |
85 |
Correct |
137 ms |
6528 KB |
Output is correct |
86 |
Correct |
130 ms |
6528 KB |
Output is correct |
87 |
Correct |
100 ms |
6528 KB |
Output is correct |
88 |
Correct |
111 ms |
6528 KB |
Output is correct |
89 |
Correct |
124 ms |
6528 KB |
Output is correct |
90 |
Correct |
137 ms |
6528 KB |
Output is correct |
91 |
Correct |
161 ms |
6528 KB |
Output is correct |
92 |
Correct |
131 ms |
6528 KB |
Output is correct |