# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
928811 |
2024-02-17T06:06:45 Z |
absolutePi |
Mecho (IOI09_mecho) |
C++17 |
|
51 ms |
7080 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 800;
int n,s;
int mx[]={1,-1,0,0},my[]={0,0,1,-1};
vector<vector<char>> grid(N,vector<char>(N));
bool valid_sit(int x,int y){
return (x>=0&&y>=0&&x<n&&y<n&&grid[x][y]=='G'&&grid[x][y]=='M');
}
bool mecho_reached(int m,int b){
return (m/s)<b;
}
int main(){
//ios::sync_with_stdio(false);
//cin.tie(0);
cin >> n >> s;
vector<pair<int,int>> bees;
pair<int,int> mecho,home;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin >> grid[i][j];
if(grid[i][j]=='H'){
bees.push_back({i,j});
}
if(grid[i][j]=='M'){
mecho = {i,j};
}
if(grid[i][j]=='D'){
home = {i,j};
}
}
}
int l=0,r=n*n;
while(l<=r){
vector<vector<bool>> visb(n,vector<bool>(n)),vism(n,vector<bool>(n));
vector<vector<int>> distb(n,vector<int>(n)),distm(n,vector<int>(n));
queue<pair<int,int>> q;
int eating_time=l+(r-l)/2;
for(auto i : bees){
q.push(i);
visb[i.first][i.second]=true;
}
while(!q.empty()){
int x,y;
tie(x,y)=q.front();
q.pop();
for(int i=0;i<4;i++){
int newx=x+mx[i];
int newy=y+my[i];
if(valid_sit(newx,newy)&&!visb[newx][newy]){
distb[newx][newy]=distb[x][y]+1;
q.push({newx,newy});
visb[newx][newy]=true;
}
}
}
q.push(mecho);
vism[mecho.first][mecho.second]=true;
if(distb[mecho.first][mecho.second]<=eating_time){q.pop();}
while(!q.empty()){
int x,y;
tie(x,y)=q.front();
q.pop();
for(int i=0;i<4;i++){
int newx=x+mx[i];
int newy=y+my[i];
if(valid_sit(newx,newy)&&!vism[newx][newy]&&mecho_reached(distm[x][y]+1,distb[newx][newy]-eating_time)){
distm[newx][newy]=distm[x][y]+1;
q.push({newx,newy});
vism[newx][newy]=true;
}
}
}
bool reached=false;
for(int i=0;i<4;i++){
int newx=home.first+mx[i];
int newy=home.second+my[i];
if(valid_sit(newx,newy)&&mecho_reached(distm[newx][newy],distb[newx][newy]-eating_time&&vism[newx][newy])){
reached=true;
}
}
if(reached){
l=eating_time+1;
}
else{
r=eating_time-1;
}
}
cout << l-1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
7 |
Incorrect |
29 ms |
6224 KB |
Output isn't correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
996 KB |
Output isn't correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
1368 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
1112 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
1112 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
1368 KB |
Output isn't correct |
33 |
Incorrect |
10 ms |
2244 KB |
Output isn't correct |
34 |
Incorrect |
10 ms |
2216 KB |
Output isn't correct |
35 |
Incorrect |
10 ms |
2144 KB |
Output isn't correct |
36 |
Incorrect |
13 ms |
2524 KB |
Output isn't correct |
37 |
Incorrect |
12 ms |
2612 KB |
Output isn't correct |
38 |
Incorrect |
13 ms |
2524 KB |
Output isn't correct |
39 |
Incorrect |
16 ms |
2936 KB |
Output isn't correct |
40 |
Incorrect |
15 ms |
2972 KB |
Output isn't correct |
41 |
Incorrect |
15 ms |
2948 KB |
Output isn't correct |
42 |
Incorrect |
19 ms |
3396 KB |
Output isn't correct |
43 |
Incorrect |
20 ms |
3400 KB |
Output isn't correct |
44 |
Incorrect |
19 ms |
3408 KB |
Output isn't correct |
45 |
Incorrect |
28 ms |
3960 KB |
Output isn't correct |
46 |
Incorrect |
29 ms |
3828 KB |
Output isn't correct |
47 |
Incorrect |
24 ms |
3872 KB |
Output isn't correct |
48 |
Incorrect |
33 ms |
4356 KB |
Output isn't correct |
49 |
Incorrect |
28 ms |
4380 KB |
Output isn't correct |
50 |
Incorrect |
29 ms |
4308 KB |
Output isn't correct |
51 |
Incorrect |
31 ms |
4980 KB |
Output isn't correct |
52 |
Incorrect |
38 ms |
4976 KB |
Output isn't correct |
53 |
Incorrect |
31 ms |
5244 KB |
Output isn't correct |
54 |
Incorrect |
39 ms |
5504 KB |
Output isn't correct |
55 |
Incorrect |
38 ms |
5564 KB |
Output isn't correct |
56 |
Incorrect |
38 ms |
5524 KB |
Output isn't correct |
57 |
Incorrect |
44 ms |
6188 KB |
Output isn't correct |
58 |
Incorrect |
44 ms |
6180 KB |
Output isn't correct |
59 |
Incorrect |
44 ms |
6180 KB |
Output isn't correct |
60 |
Incorrect |
51 ms |
6856 KB |
Output isn't correct |
61 |
Incorrect |
50 ms |
6900 KB |
Output isn't correct |
62 |
Incorrect |
51 ms |
6888 KB |
Output isn't correct |
63 |
Incorrect |
49 ms |
6856 KB |
Output isn't correct |
64 |
Incorrect |
51 ms |
6980 KB |
Output isn't correct |
65 |
Incorrect |
49 ms |
6980 KB |
Output isn't correct |
66 |
Incorrect |
50 ms |
6868 KB |
Output isn't correct |
67 |
Correct |
50 ms |
6872 KB |
Output is correct |
68 |
Incorrect |
38 ms |
6736 KB |
Output isn't correct |
69 |
Incorrect |
29 ms |
6736 KB |
Output isn't correct |
70 |
Incorrect |
32 ms |
6816 KB |
Output isn't correct |
71 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |
72 |
Incorrect |
29 ms |
6724 KB |
Output isn't correct |
73 |
Incorrect |
29 ms |
6736 KB |
Output isn't correct |
74 |
Incorrect |
30 ms |
6816 KB |
Output isn't correct |
75 |
Incorrect |
29 ms |
6736 KB |
Output isn't correct |
76 |
Incorrect |
33 ms |
6740 KB |
Output isn't correct |
77 |
Incorrect |
29 ms |
6600 KB |
Output isn't correct |
78 |
Correct |
30 ms |
6704 KB |
Output is correct |
79 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |
80 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |
81 |
Incorrect |
30 ms |
6748 KB |
Output isn't correct |
82 |
Incorrect |
30 ms |
6740 KB |
Output isn't correct |
83 |
Incorrect |
29 ms |
6736 KB |
Output isn't correct |
84 |
Incorrect |
29 ms |
6740 KB |
Output isn't correct |
85 |
Incorrect |
29 ms |
6736 KB |
Output isn't correct |
86 |
Incorrect |
29 ms |
7080 KB |
Output isn't correct |
87 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |
88 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |
89 |
Incorrect |
29 ms |
6592 KB |
Output isn't correct |
90 |
Incorrect |
29 ms |
6648 KB |
Output isn't correct |
91 |
Incorrect |
31 ms |
6740 KB |
Output isn't correct |
92 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |