# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
989666 |
2024-05-28T14:02:06 Z |
aaaaaarroz |
Mecho (IOI09_mecho) |
C++17 |
|
192 ms |
6336 KB |
#include <bits/stdc++.h>
using namespace std;
pair<int,int>inicio;
pair<int,int>final;
bool limites(int x, int y, int n){
if(x>=0&&x<n&&y>=0&&y<n){
return true;
}
else{
return false;
}
}
bool bfs(vector<vector<char>>&grid,vector<vector<int>>&bee, int &s, int n, int time){
vector<int>dx={1,0,-1,0};
vector<int>dy={0,1,0,-1};
vector<vector<int>>dist(n,vector<int>(n,-1));
dist[inicio.first][inicio.second]=0;
if((dist[inicio.first][inicio.second]+time)>bee[inicio.first][inicio.second]){
return false;
}
queue<pair<int,int>>cola;
cola.push({inicio});
while(!cola.empty()){
int x=cola.front().first;
int y=cola.front().second;
cola.pop();
for(int i=0;i<4;i++){
int xx=x+dx[i];
int yy=y+dy[i];
if(limites(xx,yy,n)&&dist[xx][yy]==-1&&((floor((dist[x][y]+1)/s)+time)<=bee[xx][yy])&&grid[xx][yy]!='T'){
dist[xx][yy]=dist[x][y]+1;
cola.push({xx,yy});
}
}
}
if(dist[final.first][final.second]==-1){
return false;
}
else{
return true;
}
}
int main() {
int n,s;
cin>>n>>s;
vector<vector<char>>grid(n,vector<char>(n));
vector<pair<int,int>>abejas;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>grid[i][j];
if(grid[i][j]=='H'){
abejas.push_back({i,j});
}
else if(grid[i][j]=='M'){
inicio={i,j};
}
else if(grid[i][j]=='D'){
final={i,j};
}
}
}
vector<vector<int>>bee(n,vector<int>(n,INT_MAX));
queue<pair<int,int>>cola;
for(int i=0;i<abejas.size();i++){
cola.push(abejas[i]);
bee[abejas[i].first][abejas[i].second]=0;
}
vector<int>dx={1,0,-1,0};
vector<int>dy={0,1,0,-1};
while(!cola.empty()){
int x=cola.front().first;
int y=cola.front().second;
cola.pop();
for(int i=0;i<4;i++){
int xx=x+dx[i];
int yy=y+dy[i];
if(limites(xx,yy,n)&&bee[xx][yy]==INT_MAX&&grid[xx][yy]!='T'&&grid[xx][yy]!='D'){
bee[xx][yy]=bee[x][y]+1;
cola.push({xx,yy});
}
}
}
if(!bfs(grid,bee,s,n,0)){
cout<<"-1\n";
return 0;
}
int l=0, r=1000000;
while(l<r){
int mid=(l+r+1)/2;
if(bfs(grid,bee,s,n,mid)){
l=mid;
}
else{
r=mid-1;
}
}
cout<<r-1<<"\n";
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<abejas.size();i++){
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
86 ms |
6280 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
9 ms |
1540 KB |
Output is correct |
34 |
Correct |
10 ms |
1624 KB |
Output is correct |
35 |
Correct |
22 ms |
1736 KB |
Output is correct |
36 |
Correct |
11 ms |
1884 KB |
Output is correct |
37 |
Correct |
11 ms |
1880 KB |
Output is correct |
38 |
Correct |
28 ms |
1952 KB |
Output is correct |
39 |
Correct |
15 ms |
2252 KB |
Output is correct |
40 |
Correct |
15 ms |
2252 KB |
Output is correct |
41 |
Correct |
35 ms |
2208 KB |
Output is correct |
42 |
Correct |
19 ms |
2684 KB |
Output is correct |
43 |
Correct |
21 ms |
2692 KB |
Output is correct |
44 |
Correct |
47 ms |
2740 KB |
Output is correct |
45 |
Correct |
21 ms |
3228 KB |
Output is correct |
46 |
Correct |
25 ms |
3148 KB |
Output is correct |
47 |
Correct |
55 ms |
3128 KB |
Output is correct |
48 |
Correct |
33 ms |
3652 KB |
Output is correct |
49 |
Correct |
26 ms |
3672 KB |
Output is correct |
50 |
Correct |
67 ms |
3724 KB |
Output is correct |
51 |
Correct |
30 ms |
4292 KB |
Output is correct |
52 |
Correct |
32 ms |
4288 KB |
Output is correct |
53 |
Correct |
77 ms |
4228 KB |
Output is correct |
54 |
Correct |
36 ms |
4844 KB |
Output is correct |
55 |
Correct |
40 ms |
4840 KB |
Output is correct |
56 |
Correct |
91 ms |
4868 KB |
Output is correct |
57 |
Correct |
38 ms |
5460 KB |
Output is correct |
58 |
Correct |
40 ms |
5520 KB |
Output is correct |
59 |
Correct |
111 ms |
5756 KB |
Output is correct |
60 |
Correct |
64 ms |
6220 KB |
Output is correct |
61 |
Correct |
48 ms |
6160 KB |
Output is correct |
62 |
Correct |
118 ms |
6200 KB |
Output is correct |
63 |
Correct |
124 ms |
6148 KB |
Output is correct |
64 |
Correct |
192 ms |
6152 KB |
Output is correct |
65 |
Correct |
161 ms |
6160 KB |
Output is correct |
66 |
Correct |
148 ms |
6188 KB |
Output is correct |
67 |
Correct |
49 ms |
5968 KB |
Output is correct |
68 |
Correct |
69 ms |
6196 KB |
Output is correct |
69 |
Correct |
68 ms |
6192 KB |
Output is correct |
70 |
Correct |
61 ms |
6228 KB |
Output is correct |
71 |
Correct |
57 ms |
6220 KB |
Output is correct |
72 |
Correct |
61 ms |
6196 KB |
Output is correct |
73 |
Correct |
56 ms |
6236 KB |
Output is correct |
74 |
Correct |
77 ms |
6252 KB |
Output is correct |
75 |
Correct |
76 ms |
6216 KB |
Output is correct |
76 |
Correct |
68 ms |
6268 KB |
Output is correct |
77 |
Correct |
68 ms |
6228 KB |
Output is correct |
78 |
Correct |
35 ms |
6176 KB |
Output is correct |
79 |
Correct |
70 ms |
6244 KB |
Output is correct |
80 |
Correct |
67 ms |
6256 KB |
Output is correct |
81 |
Correct |
71 ms |
6336 KB |
Output is correct |
82 |
Correct |
64 ms |
6232 KB |
Output is correct |
83 |
Correct |
78 ms |
6236 KB |
Output is correct |
84 |
Correct |
78 ms |
6216 KB |
Output is correct |
85 |
Correct |
80 ms |
6236 KB |
Output is correct |
86 |
Correct |
79 ms |
6232 KB |
Output is correct |
87 |
Correct |
100 ms |
6280 KB |
Output is correct |
88 |
Correct |
79 ms |
6228 KB |
Output is correct |
89 |
Correct |
88 ms |
6208 KB |
Output is correct |
90 |
Correct |
84 ms |
6184 KB |
Output is correct |
91 |
Correct |
82 ms |
6192 KB |
Output is correct |
92 |
Correct |
84 ms |
6184 KB |
Output is correct |