# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
335505 |
2020-12-12T21:24:32 Z |
DavidDamian |
Mecho (IOI09_mecho) |
C++11 |
|
250 ms |
8940 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
char forest[805][805];
int n,s;
queue<pii> Q;
int timeBees[805][805];
int dx[4]={1,-1,0,0};
int dy[4]{0,0,1,-1};
void bfsBees(vector<pii> source){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
timeBees[i][j]=INT_MAX;
}
}
for(pii u: source){
timeBees[u.first][u.second]=0;
Q.push(u);
}
while(!Q.empty()){
pii u=Q.front();
Q.pop();
for(int mov=0;mov<4;mov++){
int i=u.first+dx[mov];
int j=u.second+dy[mov];
if(i<1 || i>n) continue;
if(j<1 || j>n) continue;
if(forest[i][j]=='T' || forest[i][j]=='D') continue;
if(timeBees[i][j]==INT_MAX){
timeBees[i][j]=timeBees[u.first][u.second]+1;
Q.push(pii(i,j));
}
}
}
}
pii start;
pii goal;
int dist[805][805];
int fuel[805][805];
bool valid(int moment){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j]=INT_MAX;
}
}
if(timeBees[start.first][start.second]<=moment-1) return false;
dist[start.first][start.second]=moment-1;
fuel[start.first][start.second]=0;
Q.push(start);
while(!Q.empty()){
pii u=Q.front();
Q.pop();
if(dist[u.first][u.second]==timeBees[u.first][u.second] && fuel[u.first][u.second]==0) continue;
for(int mov=0;mov<4;mov++){
int i=u.first+dx[mov];
int j=u.second+dy[mov];
if(i<1 || i>n) continue;
if(j<1 || j>n) continue;
if(forest[i][j]=='T') continue;
int nxt_dist=dist[u.first][u.second];
if(fuel[u.first][u.second]==0)
nxt_dist++;
if(timeBees[i][j]<nxt_dist) continue;
if(dist[i][j]==INT_MAX){
dist[i][j]=nxt_dist;
fuel[i][j]=(fuel[u.first][u.second]>0)? fuel[u.first][u.second]-1 : s-1;
Q.push(pii(i,j));
}
}
}
return dist[goal.first][goal.second]!=INT_MAX;
}
int binarySearch(){
int L=1,R=10000;
int mid=(L+R)/2;
int ans=0;
while(L<=R){
mid=(L+R)/2;
if(valid(mid)){
ans=mid;
L=mid+1;
}
else{
R=mid-1;
}
}
return ans-1;
}
int main()
{
vector<pii> beeSource;
cin>>n>>s;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>forest[i][j];
if(forest[i][j]=='H'){
beeSource.push_back(pii(i,j));
}
else if(forest[i][j]=='M'){
start=pii(i,j);
}
else if(forest[i][j]=='D'){
goal=pii(i,j);
}
}
}
bfsBees(beeSource);
int last=binarySearch();
cout<<last<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
139 ms |
7660 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
876 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
620 KB |
Output is correct |
20 |
Correct |
1 ms |
620 KB |
Output is correct |
21 |
Correct |
1 ms |
620 KB |
Output is correct |
22 |
Correct |
1 ms |
620 KB |
Output is correct |
23 |
Correct |
1 ms |
748 KB |
Output is correct |
24 |
Correct |
1 ms |
748 KB |
Output is correct |
25 |
Correct |
1 ms |
748 KB |
Output is correct |
26 |
Correct |
1 ms |
876 KB |
Output is correct |
27 |
Correct |
1 ms |
876 KB |
Output is correct |
28 |
Correct |
1 ms |
876 KB |
Output is correct |
29 |
Correct |
1 ms |
896 KB |
Output is correct |
30 |
Correct |
1 ms |
876 KB |
Output is correct |
31 |
Correct |
1 ms |
876 KB |
Output is correct |
32 |
Correct |
1 ms |
876 KB |
Output is correct |
33 |
Incorrect |
23 ms |
3308 KB |
Output isn't correct |
34 |
Incorrect |
26 ms |
3692 KB |
Output isn't correct |
35 |
Correct |
33 ms |
3896 KB |
Output is correct |
36 |
Incorrect |
31 ms |
3948 KB |
Output isn't correct |
37 |
Incorrect |
35 ms |
4332 KB |
Output isn't correct |
38 |
Correct |
53 ms |
4460 KB |
Output is correct |
39 |
Incorrect |
36 ms |
4204 KB |
Output isn't correct |
40 |
Incorrect |
46 ms |
4844 KB |
Output isn't correct |
41 |
Correct |
56 ms |
4972 KB |
Output is correct |
42 |
Incorrect |
44 ms |
4588 KB |
Output isn't correct |
43 |
Incorrect |
70 ms |
5356 KB |
Output isn't correct |
44 |
Correct |
70 ms |
5484 KB |
Output is correct |
45 |
Incorrect |
53 ms |
5100 KB |
Output isn't correct |
46 |
Incorrect |
73 ms |
5868 KB |
Output isn't correct |
47 |
Correct |
87 ms |
6032 KB |
Output is correct |
48 |
Incorrect |
65 ms |
5612 KB |
Output isn't correct |
49 |
Incorrect |
89 ms |
6432 KB |
Output isn't correct |
50 |
Correct |
106 ms |
6508 KB |
Output is correct |
51 |
Incorrect |
82 ms |
5996 KB |
Output isn't correct |
52 |
Incorrect |
126 ms |
6892 KB |
Output isn't correct |
53 |
Correct |
140 ms |
7020 KB |
Output is correct |
54 |
Incorrect |
87 ms |
6508 KB |
Output isn't correct |
55 |
Incorrect |
119 ms |
7404 KB |
Output isn't correct |
56 |
Correct |
187 ms |
7532 KB |
Output is correct |
57 |
Incorrect |
108 ms |
6892 KB |
Output isn't correct |
58 |
Incorrect |
138 ms |
7980 KB |
Output isn't correct |
59 |
Correct |
174 ms |
8044 KB |
Output is correct |
60 |
Incorrect |
134 ms |
7276 KB |
Output isn't correct |
61 |
Incorrect |
154 ms |
8428 KB |
Output isn't correct |
62 |
Correct |
220 ms |
8564 KB |
Output is correct |
63 |
Correct |
153 ms |
8556 KB |
Output is correct |
64 |
Correct |
250 ms |
8556 KB |
Output is correct |
65 |
Correct |
206 ms |
8704 KB |
Output is correct |
66 |
Correct |
182 ms |
8556 KB |
Output is correct |
67 |
Correct |
167 ms |
8556 KB |
Output is correct |
68 |
Correct |
87 ms |
8568 KB |
Output is correct |
69 |
Correct |
89 ms |
8684 KB |
Output is correct |
70 |
Correct |
74 ms |
8556 KB |
Output is correct |
71 |
Correct |
81 ms |
8684 KB |
Output is correct |
72 |
Correct |
66 ms |
6636 KB |
Output is correct |
73 |
Correct |
72 ms |
8940 KB |
Output is correct |
74 |
Correct |
104 ms |
8812 KB |
Output is correct |
75 |
Correct |
121 ms |
8812 KB |
Output is correct |
76 |
Correct |
122 ms |
8940 KB |
Output is correct |
77 |
Correct |
109 ms |
8812 KB |
Output is correct |
78 |
Correct |
125 ms |
7532 KB |
Output is correct |
79 |
Correct |
94 ms |
7276 KB |
Output is correct |
80 |
Correct |
109 ms |
7276 KB |
Output is correct |
81 |
Correct |
111 ms |
7404 KB |
Output is correct |
82 |
Correct |
108 ms |
7364 KB |
Output is correct |
83 |
Correct |
140 ms |
7532 KB |
Output is correct |
84 |
Correct |
121 ms |
7372 KB |
Output is correct |
85 |
Correct |
130 ms |
7404 KB |
Output is correct |
86 |
Correct |
132 ms |
7404 KB |
Output is correct |
87 |
Correct |
129 ms |
7512 KB |
Output is correct |
88 |
Correct |
137 ms |
7664 KB |
Output is correct |
89 |
Correct |
160 ms |
7416 KB |
Output is correct |
90 |
Correct |
143 ms |
7496 KB |
Output is correct |
91 |
Correct |
138 ms |
7532 KB |
Output is correct |
92 |
Correct |
152 ms |
7532 KB |
Output is correct |