# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621406 |
2022-08-03T18:35:31 Z |
abcisosm5 |
Mecho (IOI09_mecho) |
C++17 |
|
889 ms |
2416 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 + N; 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 + N; //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 |
350 ms |
2040 KB |
Output is correct |
8 |
Correct |
1 ms |
964 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
844 KB |
Output is correct |
12 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
14 |
Correct |
3 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 |
2 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
852 KB |
Output is correct |
21 |
Correct |
2 ms |
964 KB |
Output is correct |
22 |
Correct |
2 ms |
980 KB |
Output is correct |
23 |
Correct |
3 ms |
964 KB |
Output is correct |
24 |
Correct |
2 ms |
980 KB |
Output is correct |
25 |
Correct |
3 ms |
980 KB |
Output is correct |
26 |
Correct |
3 ms |
980 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
4 ms |
980 KB |
Output is correct |
29 |
Correct |
6 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
980 KB |
Output is correct |
31 |
Correct |
4 ms |
980 KB |
Output is correct |
32 |
Correct |
3 ms |
980 KB |
Output is correct |
33 |
Correct |
90 ms |
1328 KB |
Output is correct |
34 |
Correct |
59 ms |
1324 KB |
Output is correct |
35 |
Correct |
47 ms |
1236 KB |
Output is correct |
36 |
Correct |
134 ms |
1408 KB |
Output is correct |
37 |
Correct |
69 ms |
1408 KB |
Output is correct |
38 |
Correct |
47 ms |
1364 KB |
Output is correct |
39 |
Correct |
139 ms |
1492 KB |
Output is correct |
40 |
Correct |
95 ms |
1504 KB |
Output is correct |
41 |
Correct |
64 ms |
1500 KB |
Output is correct |
42 |
Correct |
183 ms |
1576 KB |
Output is correct |
43 |
Correct |
118 ms |
1572 KB |
Output is correct |
44 |
Correct |
80 ms |
1580 KB |
Output is correct |
45 |
Correct |
244 ms |
1628 KB |
Output is correct |
46 |
Correct |
139 ms |
1636 KB |
Output is correct |
47 |
Correct |
93 ms |
1636 KB |
Output is correct |
48 |
Correct |
319 ms |
1652 KB |
Output is correct |
49 |
Correct |
178 ms |
1620 KB |
Output is correct |
50 |
Correct |
124 ms |
1664 KB |
Output is correct |
51 |
Correct |
341 ms |
1696 KB |
Output is correct |
52 |
Correct |
238 ms |
1620 KB |
Output is correct |
53 |
Correct |
152 ms |
1712 KB |
Output is correct |
54 |
Correct |
392 ms |
1748 KB |
Output is correct |
55 |
Correct |
251 ms |
1748 KB |
Output is correct |
56 |
Correct |
170 ms |
1744 KB |
Output is correct |
57 |
Correct |
469 ms |
1772 KB |
Output is correct |
58 |
Correct |
276 ms |
1748 KB |
Output is correct |
59 |
Correct |
178 ms |
1788 KB |
Output is correct |
60 |
Correct |
649 ms |
1808 KB |
Output is correct |
61 |
Correct |
360 ms |
1804 KB |
Output is correct |
62 |
Correct |
220 ms |
1828 KB |
Output is correct |
63 |
Correct |
307 ms |
1820 KB |
Output is correct |
64 |
Correct |
326 ms |
1824 KB |
Output is correct |
65 |
Correct |
316 ms |
1812 KB |
Output is correct |
66 |
Correct |
346 ms |
1848 KB |
Output is correct |
67 |
Correct |
308 ms |
1824 KB |
Output is correct |
68 |
Correct |
383 ms |
1876 KB |
Output is correct |
69 |
Correct |
290 ms |
1872 KB |
Output is correct |
70 |
Correct |
336 ms |
1884 KB |
Output is correct |
71 |
Correct |
350 ms |
1880 KB |
Output is correct |
72 |
Incorrect |
889 ms |
1884 KB |
Output isn't correct |
73 |
Incorrect |
371 ms |
2392 KB |
Output isn't correct |
74 |
Correct |
332 ms |
2400 KB |
Output is correct |
75 |
Correct |
394 ms |
2384 KB |
Output is correct |
76 |
Correct |
323 ms |
2392 KB |
Output is correct |
77 |
Correct |
335 ms |
2396 KB |
Output is correct |
78 |
Correct |
340 ms |
2396 KB |
Output is correct |
79 |
Correct |
331 ms |
2416 KB |
Output is correct |
80 |
Correct |
349 ms |
2328 KB |
Output is correct |
81 |
Correct |
316 ms |
2312 KB |
Output is correct |
82 |
Correct |
341 ms |
2316 KB |
Output is correct |
83 |
Correct |
334 ms |
2324 KB |
Output is correct |
84 |
Correct |
356 ms |
2260 KB |
Output is correct |
85 |
Correct |
340 ms |
2232 KB |
Output is correct |
86 |
Correct |
345 ms |
2236 KB |
Output is correct |
87 |
Correct |
317 ms |
2232 KB |
Output is correct |
88 |
Correct |
336 ms |
2144 KB |
Output is correct |
89 |
Correct |
310 ms |
2136 KB |
Output is correct |
90 |
Correct |
295 ms |
2148 KB |
Output is correct |
91 |
Correct |
321 ms |
2140 KB |
Output is correct |
92 |
Correct |
305 ms |
2204 KB |
Output is correct |