# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
565656 |
2022-05-21T08:17:29 Z |
Quan2003 |
Mecho (IOI09_mecho) |
C++17 |
|
289 ms |
15560 KB |
#include <bits/stdc++.h>
#include <iostream>
#include<queue>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
const int sz=1005;
int n,s;
int d1[sz][sz];
int d0[sz][sz];
bool vis1[sz][sz];
bool vis0[sz][sz];
vector<pair<int,int>>hiv;
int px,py;
int dx,dy;
ll step[sz][sz];
int movex[4]={0,0,1,-1};
int movey[4]={-1,1,0,0};
char c[sz][sz];
void bfs(vector<pair<int,int>>&a,int d[sz][sz],bool visited[sz][sz]){
queue<pair<int,int>>q;
for (auto i:a){
q.push(i);
visited[i.first][i.second]=1;
}
while (!q.empty()){
int x1=q.front().first;
int y1=q.front().second;
q.pop();
for (int i=0;i<4;i++){
int x2=x1+movex[i];
int y2=y1+movey[i];
if (x2<0 or x2>=n) continue;
if (y2<0 or y2>=n) continue;
if (c[x2][y2]!='.' or visited[x2][y2]) continue;
visited[x2][y2]=1;
d[x2][y2]=d[x1][y1]+1;
q.push({x2,y2});
}
}
}
bool bsearch(int k){
for (int i=0;i<n;i++){
for(int j=0;j<n;j++){
vis1[i][j]=0;
d1[i][j]=0;
step[i][j]=LLONG_MAX;
}
}
queue<pair<int,int>>q;
q.push({px,py});
step[px][py]=k;
while (!q.empty()){
int sx=q.front().first;
int sy=q.front().second;
q.pop();
for (int i=0;i<4;i++){
int tx=sx+movex[i];
int ty=sy+movey[i];
if (ty<0 or tx>=n) continue;
if (ty<0 or ty>=n) continue;
if (c[tx][ty]!='.' or vis1[tx][ty]) continue;
d1[tx][ty]=d1[sx][sy]+1;
int moves=k+(d1[tx][ty]+1)/s;
if (moves>=d0[tx][ty]) continue;
step[tx][ty]=moves;
vis1[tx][ty]=1;
q.push({tx,ty});
}
} for (int i=0;i<4;i++){
int tx=dx+movex[i];
int ty=dy+movey[i];
if (tx<0 or tx>=n or ty<0 or ty>=n) continue;
if (step[tx][ty]<d0[tx][ty]) return 1;
} return 0;
}
int main(){
cin>>n>>s;
for (int i=0;i<n;i++){
for(int j=0;j<n;j++){
char y; cin>>y;
c[i][j]=y;
if (c[i][j]=='G'){
c[i][j]='.';
}
if (c[i][j]=='D'){
dx=i;dy=j;
c[i][j]='.';
}
if (c[i][j]=='M'){
px=i;py=j;
} if (c[i][j]=='H'){
hiv.push_back({i,j});
}
}
} bfs(hiv,d0,vis0);
int low=0;int high=1e7;
while (high>low){
int mid=low+(high-low+1)/2;
if (bsearch(mid)) low=mid;
else high=mid-1;
}
if (!bsearch(low)) cout <<-1;
else cout <<low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
392 KB |
Output isn't correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
7 |
Correct |
146 ms |
15376 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
14 |
Correct |
1 ms |
1236 KB |
Output is correct |
15 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
21 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
22 |
Correct |
1 ms |
852 KB |
Output is correct |
23 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
26 |
Correct |
1 ms |
1236 KB |
Output is correct |
27 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
28 |
Correct |
1 ms |
1236 KB |
Output is correct |
29 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
30 |
Correct |
1 ms |
1364 KB |
Output is correct |
31 |
Incorrect |
2 ms |
1364 KB |
Output isn't correct |
32 |
Correct |
2 ms |
1432 KB |
Output is correct |
33 |
Incorrect |
14 ms |
6356 KB |
Output isn't correct |
34 |
Correct |
14 ms |
6412 KB |
Output is correct |
35 |
Correct |
31 ms |
6356 KB |
Output is correct |
36 |
Incorrect |
17 ms |
7384 KB |
Output isn't correct |
37 |
Correct |
17 ms |
7508 KB |
Output is correct |
38 |
Correct |
40 ms |
7428 KB |
Output is correct |
39 |
Incorrect |
21 ms |
8516 KB |
Output isn't correct |
40 |
Correct |
22 ms |
8492 KB |
Output is correct |
41 |
Correct |
51 ms |
8572 KB |
Output is correct |
42 |
Incorrect |
31 ms |
9668 KB |
Output isn't correct |
43 |
Correct |
29 ms |
9668 KB |
Output is correct |
44 |
Correct |
64 ms |
9608 KB |
Output is correct |
45 |
Incorrect |
36 ms |
10592 KB |
Output isn't correct |
46 |
Correct |
34 ms |
10516 KB |
Output is correct |
47 |
Correct |
79 ms |
10508 KB |
Output is correct |
48 |
Incorrect |
43 ms |
11416 KB |
Output isn't correct |
49 |
Correct |
39 ms |
11468 KB |
Output is correct |
50 |
Correct |
102 ms |
11524 KB |
Output is correct |
51 |
Incorrect |
47 ms |
12364 KB |
Output isn't correct |
52 |
Correct |
53 ms |
12376 KB |
Output is correct |
53 |
Correct |
116 ms |
12416 KB |
Output is correct |
54 |
Incorrect |
55 ms |
13380 KB |
Output isn't correct |
55 |
Correct |
57 ms |
13376 KB |
Output is correct |
56 |
Correct |
151 ms |
13392 KB |
Output is correct |
57 |
Incorrect |
67 ms |
14284 KB |
Output isn't correct |
58 |
Correct |
68 ms |
14212 KB |
Output is correct |
59 |
Correct |
170 ms |
14312 KB |
Output is correct |
60 |
Incorrect |
76 ms |
15192 KB |
Output isn't correct |
61 |
Correct |
77 ms |
15248 KB |
Output is correct |
62 |
Correct |
199 ms |
15264 KB |
Output is correct |
63 |
Incorrect |
161 ms |
15252 KB |
Output isn't correct |
64 |
Incorrect |
289 ms |
15268 KB |
Output isn't correct |
65 |
Correct |
232 ms |
15160 KB |
Output is correct |
66 |
Correct |
203 ms |
15260 KB |
Output is correct |
67 |
Correct |
189 ms |
15348 KB |
Output is correct |
68 |
Correct |
112 ms |
15288 KB |
Output is correct |
69 |
Incorrect |
107 ms |
15400 KB |
Output isn't correct |
70 |
Correct |
106 ms |
15256 KB |
Output is correct |
71 |
Correct |
102 ms |
15292 KB |
Output is correct |
72 |
Incorrect |
129 ms |
15284 KB |
Output isn't correct |
73 |
Incorrect |
129 ms |
15468 KB |
Output isn't correct |
74 |
Incorrect |
117 ms |
15488 KB |
Output isn't correct |
75 |
Correct |
125 ms |
15456 KB |
Output is correct |
76 |
Incorrect |
121 ms |
15552 KB |
Output isn't correct |
77 |
Correct |
124 ms |
15560 KB |
Output is correct |
78 |
Correct |
140 ms |
15440 KB |
Output is correct |
79 |
Correct |
109 ms |
15400 KB |
Output is correct |
80 |
Correct |
115 ms |
15436 KB |
Output is correct |
81 |
Correct |
125 ms |
15412 KB |
Output is correct |
82 |
Correct |
122 ms |
15440 KB |
Output is correct |
83 |
Correct |
137 ms |
15424 KB |
Output is correct |
84 |
Incorrect |
129 ms |
15412 KB |
Output isn't correct |
85 |
Correct |
146 ms |
15452 KB |
Output is correct |
86 |
Correct |
147 ms |
15436 KB |
Output is correct |
87 |
Correct |
135 ms |
15476 KB |
Output is correct |
88 |
Correct |
143 ms |
15400 KB |
Output is correct |
89 |
Incorrect |
158 ms |
15504 KB |
Output isn't correct |
90 |
Correct |
145 ms |
15360 KB |
Output is correct |
91 |
Correct |
145 ms |
15476 KB |
Output is correct |
92 |
Correct |
142 ms |
15416 KB |
Output is correct |