# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621375 |
2022-08-03T18:09:02 Z |
abcisosm5 |
Mecho (IOI09_mecho) |
C++17 |
|
697 ms |
3008 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();
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'){
if(grid[nx][ny] == 'D') return true;
v[nx][ny] = 'M';
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;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
848 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
844 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
289 ms |
2416 KB |
Output is correct |
8 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
852 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 |
980 KB |
Output isn't correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
22 |
Correct |
2 ms |
980 KB |
Output is correct |
23 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
24 |
Correct |
2 ms |
996 KB |
Output is correct |
25 |
Incorrect |
5 ms |
1004 KB |
Output isn't correct |
26 |
Correct |
2 ms |
980 KB |
Output is correct |
27 |
Incorrect |
3 ms |
984 KB |
Output isn't correct |
28 |
Correct |
2 ms |
980 KB |
Output is correct |
29 |
Incorrect |
3 ms |
972 KB |
Output isn't correct |
30 |
Correct |
3 ms |
980 KB |
Output is correct |
31 |
Incorrect |
4 ms |
980 KB |
Output isn't correct |
32 |
Correct |
5 ms |
980 KB |
Output is correct |
33 |
Incorrect |
74 ms |
1236 KB |
Output isn't correct |
34 |
Correct |
49 ms |
1328 KB |
Output is correct |
35 |
Correct |
37 ms |
1236 KB |
Output is correct |
36 |
Incorrect |
112 ms |
1412 KB |
Output isn't correct |
37 |
Correct |
107 ms |
1424 KB |
Output is correct |
38 |
Correct |
47 ms |
1352 KB |
Output is correct |
39 |
Incorrect |
132 ms |
1488 KB |
Output isn't correct |
40 |
Correct |
86 ms |
1496 KB |
Output is correct |
41 |
Correct |
81 ms |
1480 KB |
Output is correct |
42 |
Incorrect |
171 ms |
1568 KB |
Output isn't correct |
43 |
Correct |
112 ms |
1580 KB |
Output is correct |
44 |
Correct |
79 ms |
1496 KB |
Output is correct |
45 |
Incorrect |
288 ms |
1668 KB |
Output isn't correct |
46 |
Correct |
145 ms |
1664 KB |
Output is correct |
47 |
Correct |
118 ms |
1672 KB |
Output is correct |
48 |
Incorrect |
343 ms |
1760 KB |
Output isn't correct |
49 |
Correct |
171 ms |
1788 KB |
Output is correct |
50 |
Correct |
105 ms |
1748 KB |
Output is correct |
51 |
Incorrect |
345 ms |
1860 KB |
Output isn't correct |
52 |
Correct |
197 ms |
1860 KB |
Output is correct |
53 |
Correct |
136 ms |
1856 KB |
Output is correct |
54 |
Incorrect |
331 ms |
1972 KB |
Output isn't correct |
55 |
Correct |
205 ms |
2016 KB |
Output is correct |
56 |
Correct |
156 ms |
1984 KB |
Output is correct |
57 |
Incorrect |
379 ms |
2072 KB |
Output isn't correct |
58 |
Correct |
267 ms |
2064 KB |
Output is correct |
59 |
Correct |
173 ms |
2004 KB |
Output is correct |
60 |
Incorrect |
455 ms |
2208 KB |
Output isn't correct |
61 |
Correct |
302 ms |
2188 KB |
Output is correct |
62 |
Correct |
212 ms |
2200 KB |
Output is correct |
63 |
Correct |
295 ms |
2132 KB |
Output is correct |
64 |
Correct |
287 ms |
2200 KB |
Output is correct |
65 |
Correct |
268 ms |
2200 KB |
Output is correct |
66 |
Incorrect |
301 ms |
2196 KB |
Output isn't correct |
67 |
Correct |
274 ms |
2200 KB |
Output is correct |
68 |
Correct |
285 ms |
2260 KB |
Output is correct |
69 |
Correct |
252 ms |
2260 KB |
Output is correct |
70 |
Correct |
287 ms |
2260 KB |
Output is correct |
71 |
Correct |
321 ms |
2260 KB |
Output is correct |
72 |
Incorrect |
697 ms |
2252 KB |
Output isn't correct |
73 |
Incorrect |
314 ms |
2764 KB |
Output isn't correct |
74 |
Correct |
289 ms |
3008 KB |
Output is correct |
75 |
Correct |
312 ms |
2772 KB |
Output is correct |
76 |
Correct |
307 ms |
2772 KB |
Output is correct |
77 |
Correct |
312 ms |
2920 KB |
Output is correct |
78 |
Correct |
319 ms |
2700 KB |
Output is correct |
79 |
Correct |
358 ms |
2704 KB |
Output is correct |
80 |
Correct |
325 ms |
2704 KB |
Output is correct |
81 |
Correct |
328 ms |
2804 KB |
Output is correct |
82 |
Correct |
351 ms |
2748 KB |
Output is correct |
83 |
Correct |
347 ms |
2624 KB |
Output is correct |
84 |
Correct |
308 ms |
2620 KB |
Output is correct |
85 |
Correct |
402 ms |
2680 KB |
Output is correct |
86 |
Correct |
330 ms |
2644 KB |
Output is correct |
87 |
Correct |
332 ms |
2612 KB |
Output is correct |
88 |
Correct |
347 ms |
2520 KB |
Output is correct |
89 |
Correct |
345 ms |
2556 KB |
Output is correct |
90 |
Correct |
355 ms |
2520 KB |
Output is correct |
91 |
Correct |
324 ms |
2524 KB |
Output is correct |
92 |
Correct |
373 ms |
2520 KB |
Output is correct |