# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
255234 |
2020-07-31T15:34:57 Z |
DavidDamian |
Mecho (IOI09_mecho) |
C++11 |
|
268 ms |
11644 KB |
#include <bits/stdc++.h>
using namespace std;
struct node
{
int i,j;
node(){}
node(int i,int j) : i(i),j(j){}
};
int n,s;
char board[805][805];
int bee[805][805];
int d[805][805];
int color[805][805];
int fuel[805][805];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
queue<node> Q;
node start,finish;
void bfsBee()
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
bee[i][j]=INT_MAX;
if(board[i][j]=='H'){
Q.push(node(i,j));
bee[i][j]=0;
color[i][j]=-1;
}
}
}
while(Q.size()){
node u=Q.front();Q.pop();
for(int mov=0;mov<4;mov++){
int i=u.i+dx[mov];
int j=u.j+dy[mov];
if(i<1 || i>n) continue;
if(j<1 || j>n) continue;
if(board[i][j]=='T' || board[i][j]=='D') continue;
if(color[i][j]==0){
color[i][j]=-1;
Q.push(node(i,j));
bee[i][j]=bee[u.i][u.j]+1;
}
}
}
}
void bfsMecho(int init_d)
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d[i][j]=INT_MAX;
color[i][j]=0;
}
}
if(bee[start.i][start.j]<=init_d-1) return;
d[start.i][start.j]=init_d-1;
fuel[start.i][start.j]=0;
color[start.i][start.j]=init_d;
Q.push(start);
while(Q.size()){
node u=Q.front();Q.pop();
if(d[u.i][u.j]==bee[u.i][u.j]) continue;
for(int mov=0;mov<4;mov++){
int i=u.i+dx[mov];
int j=u.j+dy[mov];
if(i<1 || i>n) continue;
if(j<1 || j>n) continue;
if(board[i][j]=='T') continue;
if(color[i][j]!=init_d){
d[i][j]=(fuel[u.i][u.j]>0)? d[u.i][u.j] : d[u.i][u.j]+1;
if(bee[i][j]<d[i][j]) continue;
fuel[i][j]=(fuel[u.i][u.j]>0)? fuel[u.i][u.j]-1 : s-1;
color[i][j]=init_d;
Q.push(node(i,j));
}
}
}
}
bool valid(int k)
{
bfsMecho(k);
return d[finish.i][finish.j]!=INT_MAX;
}
int binarySearch()
{
int k=0;
for(int b=10000;b>=1;b/=2){
while(valid(k+b)) k+=b;
}
return (k==0)? -1 : k;
}
int main()
{
ios_base::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>>board[i][j];
if(board[i][j]=='M') start={i,j};
if(board[i][j]=='D') finish={i,j};
}
}
bfsBee();
int maximum=binarySearch();
cout<<maximum<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
135 ms |
10232 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
544 KB |
Output is correct |
12 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
14 |
Correct |
1 ms |
1024 KB |
Output is correct |
15 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Incorrect |
1 ms |
768 KB |
Output isn't correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
24 |
Correct |
1 ms |
896 KB |
Output is correct |
25 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
26 |
Correct |
1 ms |
1024 KB |
Output is correct |
27 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
28 |
Correct |
1 ms |
1152 KB |
Output is correct |
29 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
30 |
Correct |
1 ms |
1152 KB |
Output is correct |
31 |
Incorrect |
2 ms |
1152 KB |
Output isn't correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Incorrect |
10 ms |
4480 KB |
Output isn't correct |
34 |
Correct |
11 ms |
4864 KB |
Output is correct |
35 |
Correct |
33 ms |
5240 KB |
Output is correct |
36 |
Incorrect |
14 ms |
5120 KB |
Output isn't correct |
37 |
Correct |
14 ms |
5504 KB |
Output is correct |
38 |
Correct |
40 ms |
5888 KB |
Output is correct |
39 |
Incorrect |
20 ms |
5760 KB |
Output isn't correct |
40 |
Correct |
19 ms |
6272 KB |
Output is correct |
41 |
Correct |
61 ms |
6520 KB |
Output is correct |
42 |
Incorrect |
26 ms |
6272 KB |
Output isn't correct |
43 |
Correct |
21 ms |
6912 KB |
Output is correct |
44 |
Correct |
60 ms |
7296 KB |
Output is correct |
45 |
Incorrect |
34 ms |
7040 KB |
Output isn't correct |
46 |
Correct |
29 ms |
7672 KB |
Output is correct |
47 |
Correct |
77 ms |
7896 KB |
Output is correct |
48 |
Incorrect |
49 ms |
7552 KB |
Output isn't correct |
49 |
Correct |
42 ms |
8440 KB |
Output is correct |
50 |
Correct |
96 ms |
8448 KB |
Output is correct |
51 |
Incorrect |
57 ms |
8064 KB |
Output isn't correct |
52 |
Correct |
61 ms |
8960 KB |
Output is correct |
53 |
Correct |
117 ms |
9216 KB |
Output is correct |
54 |
Incorrect |
76 ms |
8704 KB |
Output isn't correct |
55 |
Correct |
66 ms |
9720 KB |
Output is correct |
56 |
Correct |
135 ms |
9848 KB |
Output is correct |
57 |
Incorrect |
94 ms |
9344 KB |
Output isn't correct |
58 |
Correct |
81 ms |
10360 KB |
Output is correct |
59 |
Correct |
182 ms |
10580 KB |
Output is correct |
60 |
Incorrect |
117 ms |
9956 KB |
Output isn't correct |
61 |
Correct |
96 ms |
11004 KB |
Output is correct |
62 |
Correct |
186 ms |
11128 KB |
Output is correct |
63 |
Incorrect |
128 ms |
11256 KB |
Output isn't correct |
64 |
Correct |
268 ms |
11256 KB |
Output is correct |
65 |
Correct |
199 ms |
11128 KB |
Output is correct |
66 |
Incorrect |
185 ms |
11256 KB |
Output isn't correct |
67 |
Correct |
139 ms |
11256 KB |
Output is correct |
68 |
Incorrect |
61 ms |
11000 KB |
Output isn't correct |
69 |
Correct |
65 ms |
11264 KB |
Output is correct |
70 |
Correct |
50 ms |
11256 KB |
Output is correct |
71 |
Correct |
56 ms |
11256 KB |
Output is correct |
72 |
Incorrect |
45 ms |
9336 KB |
Output isn't correct |
73 |
Incorrect |
57 ms |
11588 KB |
Output isn't correct |
74 |
Correct |
84 ms |
11512 KB |
Output is correct |
75 |
Correct |
125 ms |
11512 KB |
Output is correct |
76 |
Correct |
109 ms |
11644 KB |
Output is correct |
77 |
Correct |
123 ms |
11512 KB |
Output is correct |
78 |
Correct |
107 ms |
10296 KB |
Output is correct |
79 |
Correct |
69 ms |
9720 KB |
Output is correct |
80 |
Correct |
84 ms |
9848 KB |
Output is correct |
81 |
Correct |
98 ms |
10104 KB |
Output is correct |
82 |
Correct |
87 ms |
9976 KB |
Output is correct |
83 |
Incorrect |
107 ms |
10104 KB |
Output isn't correct |
84 |
Correct |
99 ms |
9980 KB |
Output is correct |
85 |
Correct |
123 ms |
10120 KB |
Output is correct |
86 |
Correct |
106 ms |
10104 KB |
Output is correct |
87 |
Correct |
123 ms |
10104 KB |
Output is correct |
88 |
Incorrect |
98 ms |
10236 KB |
Output isn't correct |
89 |
Correct |
126 ms |
10156 KB |
Output is correct |
90 |
Correct |
123 ms |
10104 KB |
Output is correct |
91 |
Correct |
144 ms |
10232 KB |
Output is correct |
92 |
Correct |
118 ms |
10232 KB |
Output is correct |