# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
892963 |
2023-12-26T09:15:30 Z |
ilef |
Mecho (IOI09_mecho) |
C++14 |
|
191 ms |
25756 KB |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=INT_MAX;
int n,s;
bool safe(int i,int j){
return i>=0 && i<n && j>=0 && j<n;
}
int di[4]={0,0,-1,1};
int dj[4]={1,-1,0,0};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>s;
char mat[n][n];
int dist1[n][n];
int dist2[n][n];
int homex,homey;
int honx,hony;
queue<pair<int,int>>q;
bool vis1[n][n];
bool vis2[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
vis1[i][j]=false;
vis2[i][j]=false;
dist1[i][j]=inf;
dist2[i][j]=inf;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>mat[i][j];
if(mat[i][j]=='M'){
honx=i;
hony=j;
}
if(mat[i][j]=='D'){
homex=i;
homey=j;
}
if(mat[i][j]=='H'){
q.push({i,j});
dist1[i][j]=0;
vis1[i][j]=true;
}
}
}
while(!q.empty()){
const auto &[i,j]=q.front();
q.pop();
for(int l=0;l<4;l++){
int x=i+di[l];
int y=j+dj[l];
if(safe(x,y) && !vis1[x][y] && (mat[x][y]=='G'||mat[x][y]=='M')){
dist1[x][y]=dist1[i][j]+1;
vis1[x][y]=true;
q.push({x,y});
}
}
}
//bool reached=false;
int ll=0,rr=n*n;
int ans=-1;
while(ll<=rr){
int mid=(ll+rr)/2;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
vis2[i][j]=false;
dist2[i][j]=inf;
}
}
if(mid<dist1[honx][hony]){
dist2[honx][hony]=0;
vis2[honx][hony]=true;
q.push({honx,hony});
}
while(!q.empty()){
const auto &[i,j]=q.front();
q.pop();
for(int l=0;l<4;l++){
int x=i+di[l];
int y=j+dj[l];
double dss=dist2[i][j]+1;
dss/=s;
int ds=ceil(dss);
if(safe(x,y) && (mat[x][y]=='G'|| mat[x][y]=='D')&& !vis2[x][y] &&(ds<(dist1[x][y]-mid))){
dist2[x][y]=dist2[i][j]+1;
vis2[x][y]=true;
q.push({x,y});
}
}
}
bool reached=false;
for(int i=0;i<4;i++){
int x=homex+di[i];
int y=homey+dj[i];
if(safe(x,y) && vis2[x][y]){
double dss=dist2[x][y];
dss/=s;
int ds=ceil(dss);
if(ds<dist1[x][y]-mid){
reached=true;}
}
}
if(reached){
ans=mid;
ll=mid+1;
}
else{
//ans=mid;
rr=mid-1;
}
}
cout<<ans+1<<endl;
}
Compilation message
mecho.cpp: In function 'int32_t main()':
mecho.cpp:52:21: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
52 | const auto &[i,j]=q.front();
| ^
mecho.cpp:83:21: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
83 | const auto &[i,j]=q.front();
| ^
mecho.cpp:102:13: warning: 'homey' may be used uninitialized in this function [-Wmaybe-uninitialized]
102 | int y=homey+dj[i];
| ^
mecho.cpp:101:13: warning: 'homex' may be used uninitialized in this function [-Wmaybe-uninitialized]
101 | int x=homex+di[i];
| ^
mecho.cpp:78:30: warning: 'hony' may be used uninitialized in this function [-Wmaybe-uninitialized]
78 | dist2[honx][hony]=0;
| ~~~~~~~~~~~~~~~~~^~
mecho.cpp:78:30: warning: 'honx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
104 ms |
12556 KB |
Output is correct |
8 |
Incorrect |
0 ms |
344 KB |
Output isn't 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Incorrect |
0 ms |
780 KB |
Output isn't correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Incorrect |
6 ms |
2692 KB |
Output isn't correct |
34 |
Correct |
5 ms |
2728 KB |
Output is correct |
35 |
Correct |
20 ms |
2648 KB |
Output is correct |
36 |
Incorrect |
6 ms |
3420 KB |
Output isn't correct |
37 |
Correct |
7 ms |
3420 KB |
Output is correct |
38 |
Correct |
32 ms |
3444 KB |
Output is correct |
39 |
Incorrect |
8 ms |
4440 KB |
Output isn't correct |
40 |
Correct |
10 ms |
4188 KB |
Output is correct |
41 |
Correct |
44 ms |
4188 KB |
Output is correct |
42 |
Incorrect |
10 ms |
5100 KB |
Output isn't correct |
43 |
Correct |
11 ms |
4956 KB |
Output is correct |
44 |
Correct |
45 ms |
4956 KB |
Output is correct |
45 |
Incorrect |
12 ms |
5976 KB |
Output isn't correct |
46 |
Correct |
13 ms |
5980 KB |
Output is correct |
47 |
Correct |
59 ms |
6068 KB |
Output is correct |
48 |
Incorrect |
15 ms |
7000 KB |
Output isn't correct |
49 |
Correct |
17 ms |
7204 KB |
Output is correct |
50 |
Correct |
94 ms |
7272 KB |
Output is correct |
51 |
Incorrect |
17 ms |
8280 KB |
Output isn't correct |
52 |
Correct |
19 ms |
8284 KB |
Output is correct |
53 |
Correct |
91 ms |
8300 KB |
Output is correct |
54 |
Incorrect |
19 ms |
9308 KB |
Output isn't correct |
55 |
Correct |
21 ms |
9304 KB |
Output is correct |
56 |
Correct |
108 ms |
9560 KB |
Output is correct |
57 |
Incorrect |
22 ms |
10844 KB |
Output isn't correct |
58 |
Correct |
25 ms |
10844 KB |
Output is correct |
59 |
Correct |
108 ms |
10840 KB |
Output is correct |
60 |
Incorrect |
25 ms |
12120 KB |
Output isn't correct |
61 |
Correct |
28 ms |
12124 KB |
Output is correct |
62 |
Correct |
131 ms |
12344 KB |
Output is correct |
63 |
Correct |
90 ms |
12340 KB |
Output is correct |
64 |
Correct |
191 ms |
12348 KB |
Output is correct |
65 |
Correct |
127 ms |
12124 KB |
Output is correct |
66 |
Incorrect |
136 ms |
12124 KB |
Output isn't correct |
67 |
Incorrect |
104 ms |
12336 KB |
Output isn't correct |
68 |
Correct |
50 ms |
12376 KB |
Output is correct |
69 |
Correct |
47 ms |
12380 KB |
Output is correct |
70 |
Correct |
45 ms |
12384 KB |
Output is correct |
71 |
Correct |
41 ms |
12376 KB |
Output is correct |
72 |
Incorrect |
37 ms |
12380 KB |
Output isn't correct |
73 |
Runtime error |
34 ms |
25756 KB |
Execution killed with signal 11 |
74 |
Runtime error |
34 ms |
25628 KB |
Execution killed with signal 11 |
75 |
Correct |
77 ms |
12816 KB |
Output is correct |
76 |
Correct |
76 ms |
12888 KB |
Output is correct |
77 |
Runtime error |
79 ms |
25560 KB |
Execution killed with signal 11 |
78 |
Incorrect |
73 ms |
12636 KB |
Output isn't correct |
79 |
Correct |
56 ms |
12636 KB |
Output is correct |
80 |
Correct |
68 ms |
12632 KB |
Output is correct |
81 |
Correct |
76 ms |
12636 KB |
Output is correct |
82 |
Correct |
67 ms |
12636 KB |
Output is correct |
83 |
Correct |
90 ms |
12884 KB |
Output is correct |
84 |
Correct |
73 ms |
12756 KB |
Output is correct |
85 |
Correct |
75 ms |
12752 KB |
Output is correct |
86 |
Correct |
89 ms |
12752 KB |
Output is correct |
87 |
Correct |
85 ms |
12752 KB |
Output is correct |
88 |
Correct |
81 ms |
12788 KB |
Output is correct |
89 |
Correct |
94 ms |
12636 KB |
Output is correct |
90 |
Correct |
102 ms |
12600 KB |
Output is correct |
91 |
Correct |
89 ms |
12636 KB |
Output is correct |
92 |
Correct |
92 ms |
12636 KB |
Output is correct |