# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621403 |
2022-08-03T18:31:05 Z |
abcisosm5 |
Mecho (IOI09_mecho) |
C++17 |
|
801 ms |
2876 KB |
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
#define f first
#define s second
int N, S;
const int MN = 800;
char grid[MN][MN] = {{}};
vector<pi> hives;
pi M; pi D;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void movebees(queue<pi> (&b), char (&v)[MN][MN], int t){
for(int i = 0; i < t; i++){
queue<pi> nextb;
while(!b.empty()){
pi p = b.front(); b.pop();
for(int d = 0; d < 4; d++){
int nx = p.f + dx[d]; int ny = p.s + dy[d];
if(nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
if(v[nx][ny] != 'B' && grid[nx][ny] == 'G'){
v[nx][ny] = 'B';
nextb.push({nx, ny});
}
}
}
b = nextb;
}
}
bool movemecho(queue<pi> (&m), char (&v)[MN][MN]){
for(int i = 0; i < S; i++){
queue<pi> nextm;
while(!m.empty()){
pi p = m.front(); m.pop();
if(v[p.f][p.s] == 'B') continue; //invalidate positions that are now occupied by bees
for(int d = 0; d < 4; d++){
int nx = p.f + dx[d]; int ny = p.s + dy[d];
if(nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
if(!v[nx][ny] && grid[nx][ny] != 'T'){
v[nx][ny] = 'M';
if(grid[nx][ny] == 'D') return true;
nextm.push({nx, ny});
}
}
}
m = nextm;
}
return false;
}
bool works(int t){ //O(N^2)
char visited[MN][MN] = {{}};
queue<pi> bees;
for(pi p : hives){
bees.push(p);
visited[p.first][p.second] = 'B';
}
movebees(bees, visited, t);
queue<pi> mecho; mecho.push(M); visited[M.f][M.s] = 'M';
for(int i = 0; i < N*N/2; i++){
//first, move mecho S steps
if(mecho.empty()) break;
bool success = movemecho(mecho, visited);
if(success) return true;
//then, move bees 1 step
movebees(bees, visited, 1);
}
return false;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> N >> S;
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
cin >> grid[i][j];
if(grid[i][j] == 'M') M = {i, j};
if(grid[i][j] == 'D') D = {i, j};
if(grid[i][j] == 'H') hives.push_back({i,j});
}
}
int lo = -1; int hi = N*N/2; //amount of head start to bees
while(lo < hi){ // in total, O(N^2 log N)
int mid = lo + (hi - lo + 1) / 2;
if(works(mid)){
lo = mid;
} else {
hi = mid - 1;
}
}
cout << lo;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
380 ms |
2408 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
840 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
988 KB |
Output isn't correct |
14 |
Correct |
2 ms |
964 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
2 ms |
968 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
2 ms |
972 KB |
Output is correct |
22 |
Correct |
2 ms |
980 KB |
Output is correct |
23 |
Correct |
2 ms |
980 KB |
Output is correct |
24 |
Correct |
3 ms |
980 KB |
Output is correct |
25 |
Correct |
3 ms |
980 KB |
Output is correct |
26 |
Correct |
2 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
2 ms |
980 KB |
Output is correct |
29 |
Correct |
3 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
992 KB |
Output is correct |
31 |
Correct |
3 ms |
968 KB |
Output is correct |
32 |
Correct |
3 ms |
980 KB |
Output is correct |
33 |
Correct |
94 ms |
1328 KB |
Output is correct |
34 |
Correct |
60 ms |
1324 KB |
Output is correct |
35 |
Correct |
43 ms |
1236 KB |
Output is correct |
36 |
Correct |
134 ms |
1368 KB |
Output is correct |
37 |
Correct |
83 ms |
1412 KB |
Output is correct |
38 |
Correct |
48 ms |
1408 KB |
Output is correct |
39 |
Correct |
154 ms |
1500 KB |
Output is correct |
40 |
Correct |
103 ms |
1492 KB |
Output is correct |
41 |
Correct |
74 ms |
1492 KB |
Output is correct |
42 |
Correct |
178 ms |
1568 KB |
Output is correct |
43 |
Correct |
120 ms |
1568 KB |
Output is correct |
44 |
Correct |
84 ms |
1584 KB |
Output is correct |
45 |
Correct |
209 ms |
1660 KB |
Output is correct |
46 |
Correct |
156 ms |
1672 KB |
Output is correct |
47 |
Correct |
102 ms |
1676 KB |
Output is correct |
48 |
Correct |
326 ms |
1780 KB |
Output is correct |
49 |
Correct |
178 ms |
1764 KB |
Output is correct |
50 |
Correct |
142 ms |
1748 KB |
Output is correct |
51 |
Correct |
341 ms |
1852 KB |
Output is correct |
52 |
Correct |
206 ms |
1876 KB |
Output is correct |
53 |
Correct |
159 ms |
1884 KB |
Output is correct |
54 |
Correct |
358 ms |
1968 KB |
Output is correct |
55 |
Correct |
231 ms |
1956 KB |
Output is correct |
56 |
Correct |
152 ms |
1976 KB |
Output is correct |
57 |
Correct |
411 ms |
2068 KB |
Output is correct |
58 |
Correct |
257 ms |
2124 KB |
Output is correct |
59 |
Correct |
173 ms |
2088 KB |
Output is correct |
60 |
Correct |
457 ms |
2180 KB |
Output is correct |
61 |
Correct |
388 ms |
2184 KB |
Output is correct |
62 |
Correct |
227 ms |
2204 KB |
Output is correct |
63 |
Correct |
305 ms |
2320 KB |
Output is correct |
64 |
Correct |
310 ms |
2188 KB |
Output is correct |
65 |
Correct |
272 ms |
2196 KB |
Output is correct |
66 |
Correct |
296 ms |
2196 KB |
Output is correct |
67 |
Correct |
326 ms |
2192 KB |
Output is correct |
68 |
Correct |
339 ms |
2240 KB |
Output is correct |
69 |
Correct |
337 ms |
2260 KB |
Output is correct |
70 |
Correct |
334 ms |
2260 KB |
Output is correct |
71 |
Correct |
303 ms |
2260 KB |
Output is correct |
72 |
Incorrect |
801 ms |
2260 KB |
Output isn't correct |
73 |
Incorrect |
391 ms |
2756 KB |
Output isn't correct |
74 |
Correct |
337 ms |
2816 KB |
Output is correct |
75 |
Correct |
334 ms |
2840 KB |
Output is correct |
76 |
Correct |
370 ms |
2876 KB |
Output is correct |
77 |
Correct |
305 ms |
2772 KB |
Output is correct |
78 |
Correct |
359 ms |
2748 KB |
Output is correct |
79 |
Correct |
327 ms |
2692 KB |
Output is correct |
80 |
Correct |
327 ms |
2780 KB |
Output is correct |
81 |
Correct |
329 ms |
2696 KB |
Output is correct |
82 |
Correct |
322 ms |
2744 KB |
Output is correct |
83 |
Correct |
403 ms |
2604 KB |
Output is correct |
84 |
Correct |
343 ms |
2752 KB |
Output is correct |
85 |
Correct |
361 ms |
2608 KB |
Output is correct |
86 |
Correct |
337 ms |
2612 KB |
Output is correct |
87 |
Correct |
363 ms |
2600 KB |
Output is correct |
88 |
Correct |
317 ms |
2516 KB |
Output is correct |
89 |
Correct |
318 ms |
2520 KB |
Output is correct |
90 |
Correct |
407 ms |
2524 KB |
Output is correct |
91 |
Correct |
400 ms |
2520 KB |
Output is correct |
92 |
Correct |
353 ms |
2520 KB |
Output is correct |