# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
989651 |
2024-05-28T13:18:57 Z |
aaaaaarroz |
Mecho (IOI09_mecho) |
C++17 |
|
191 ms |
6756 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&&((ceil((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,-1));
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]==-1&&grid[xx][yy]!='T'){
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<<l-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 |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
85 ms |
6288 KB |
Output isn't correct |
8 |
Correct |
0 ms |
348 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 |
436 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 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 |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 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 |
1 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 |
1636 KB |
Output is correct |
34 |
Correct |
9 ms |
1640 KB |
Output is correct |
35 |
Correct |
23 ms |
1836 KB |
Output is correct |
36 |
Correct |
11 ms |
1880 KB |
Output is correct |
37 |
Correct |
12 ms |
1884 KB |
Output is correct |
38 |
Correct |
27 ms |
1972 KB |
Output is correct |
39 |
Correct |
15 ms |
2384 KB |
Output is correct |
40 |
Correct |
15 ms |
2412 KB |
Output is correct |
41 |
Correct |
35 ms |
2472 KB |
Output is correct |
42 |
Correct |
19 ms |
2852 KB |
Output is correct |
43 |
Correct |
20 ms |
2920 KB |
Output is correct |
44 |
Correct |
46 ms |
2928 KB |
Output is correct |
45 |
Correct |
21 ms |
3324 KB |
Output is correct |
46 |
Correct |
22 ms |
3356 KB |
Output is correct |
47 |
Correct |
55 ms |
3456 KB |
Output is correct |
48 |
Correct |
26 ms |
3948 KB |
Output is correct |
49 |
Correct |
28 ms |
3908 KB |
Output is correct |
50 |
Correct |
65 ms |
3848 KB |
Output is correct |
51 |
Correct |
30 ms |
4588 KB |
Output is correct |
52 |
Correct |
31 ms |
4540 KB |
Output is correct |
53 |
Correct |
80 ms |
4592 KB |
Output is correct |
54 |
Correct |
35 ms |
5120 KB |
Output is correct |
55 |
Correct |
38 ms |
5208 KB |
Output is correct |
56 |
Correct |
92 ms |
5216 KB |
Output is correct |
57 |
Correct |
40 ms |
5828 KB |
Output is correct |
58 |
Correct |
39 ms |
5880 KB |
Output is correct |
59 |
Correct |
108 ms |
5860 KB |
Output is correct |
60 |
Correct |
43 ms |
6632 KB |
Output is correct |
61 |
Correct |
45 ms |
6672 KB |
Output is correct |
62 |
Correct |
117 ms |
6584 KB |
Output is correct |
63 |
Correct |
129 ms |
6564 KB |
Output is correct |
64 |
Correct |
191 ms |
6552 KB |
Output is correct |
65 |
Correct |
173 ms |
6608 KB |
Output is correct |
66 |
Correct |
155 ms |
6532 KB |
Output is correct |
67 |
Correct |
42 ms |
6484 KB |
Output is correct |
68 |
Correct |
68 ms |
6640 KB |
Output is correct |
69 |
Correct |
70 ms |
6604 KB |
Output is correct |
70 |
Correct |
63 ms |
6644 KB |
Output is correct |
71 |
Correct |
56 ms |
6644 KB |
Output is correct |
72 |
Correct |
55 ms |
6624 KB |
Output is correct |
73 |
Correct |
58 ms |
6684 KB |
Output is correct |
74 |
Correct |
74 ms |
6644 KB |
Output is correct |
75 |
Correct |
73 ms |
6696 KB |
Output is correct |
76 |
Correct |
67 ms |
6756 KB |
Output is correct |
77 |
Correct |
69 ms |
6676 KB |
Output is correct |
78 |
Correct |
36 ms |
6480 KB |
Output is correct |
79 |
Correct |
70 ms |
6680 KB |
Output is correct |
80 |
Correct |
67 ms |
6604 KB |
Output is correct |
81 |
Correct |
72 ms |
6604 KB |
Output is correct |
82 |
Correct |
63 ms |
6696 KB |
Output is correct |
83 |
Correct |
78 ms |
6628 KB |
Output is correct |
84 |
Correct |
82 ms |
6468 KB |
Output is correct |
85 |
Correct |
78 ms |
6616 KB |
Output is correct |
86 |
Correct |
77 ms |
6636 KB |
Output is correct |
87 |
Correct |
76 ms |
6680 KB |
Output is correct |
88 |
Correct |
83 ms |
6640 KB |
Output is correct |
89 |
Correct |
86 ms |
6612 KB |
Output is correct |
90 |
Correct |
82 ms |
6632 KB |
Output is correct |
91 |
Correct |
82 ms |
6644 KB |
Output is correct |
92 |
Correct |
81 ms |
6612 KB |
Output is correct |