# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484088 |
2021-11-02T05:43:05 Z |
nehasane |
Mecho (IOI09_mecho) |
C++14 |
|
262 ms |
7628 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 800;
vector <string> field(MAX_N);
bool bees_visited[MAX_N][MAX_N], mecho_visited[MAX_N][MAX_N];
int mecho_dis[MAX_N][MAX_N], bees_dis[MAX_N][MAX_N];
queue <pair <int, int>> mecho_q, bees_q;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int n, s;
bool valid_sq(int x, int y){
if (x >= 0 && x < n && y >= 0 && y < n && field[x][y] != 'T' && field[x][y] != 'H')
return true;
return false;
}
void update_field(queue <pair <int, int>> &q, int max_steps, bool (&visited)[MAX_N][MAX_N], bool (&visited2)[MAX_N][MAX_N], int (&dis)[MAX_N][MAX_N], bool is_mecho){
while (!q.empty() && dis[q.front().first][q.front().second] <= max_steps){
int x = q.front().first, y = q.front().second;
q.pop();
if (is_mecho && visited2[x][y])
continue;
for (int i = 0; i < 4; i++){
if (valid_sq(x + dx[i], y + dy[i]) && !visited[x+dx[i]][y+dy[i]] && !visited2[x+dx[i]][y+dy[i]]){
q.push({x+dx[i], y+dy[i]});
visited[x+dx[i]][y+dy[i]] = true;
dis[x+dx[i]][y+dy[i]] = dis[x][y] + 1;
}
}
}
}
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n >> s;
for (int i = 0; i < n; i++)
cin >> field[i];
vector <pair <int, int>> hives;
int startx, starty, home_x, home_y;
//find Mecho's position
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (field[i][j] == 'M'){
startx = i;
starty = j;
}else if (field[i][j] == 'H'){
hives.push_back({i, j});
}else if (field[i][j] == 'D'){
home_x = i;
home_y = j;
}
}
}
int l = 0, r = 2*n;
while (l <= r){
int eating_time = (l + r) / 2;
memset(bees_visited, false, sizeof(bees_visited));
memset(mecho_visited, false, sizeof(mecho_visited));
memset(bees_dis, 0, sizeof(bees_dis));
memset(mecho_dis, 0, sizeof(mecho_dis));
//simulate
for (auto i : hives){
bees_q.push({i.first, i.second});
bees_visited[i.first][i.second] = true;
}
if (eating_time > 0)
update_field(bees_q, eating_time, bees_visited, bees_visited, bees_dis, false);
mecho_q.push({startx, starty});
for (int i = eating_time; i <= n*2-2 && !bees_q.empty() && !mecho_q.empty(); i++){
while (!bees_q.empty() && bees_dis[bees_q.front().first][bees_q.front().second] != 0){
bees_dis[bees_q.front().first][bees_q.front().second] = 0;
bees_q.push({bees_q.front().first, bees_q.front().second});
bees_q.pop();
}while (!mecho_q.empty() && mecho_dis[mecho_q.front().first][mecho_q.front().second] != 0){
mecho_dis[mecho_q.front().first][mecho_q.front().second] = 0;
mecho_q.push({mecho_q.front().first, mecho_q.front().second});
mecho_q.pop();
}
update_field(mecho_q, s, mecho_visited, bees_visited, mecho_dis, true);
if (mecho_visited[home_x][home_y])
break;
update_field(bees_q, 1, bees_visited, bees_visited, bees_dis, false);
}
if (mecho_visited[home_x][home_y])
l = eating_time + 1;
else
r = eating_time - 1;
//empty_queues
while (!bees_q.empty())
bees_q.pop();
while (!mecho_q.empty())
mecho_q.pop();
}
cout << l - 1 << '\n';
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:84:41: warning: 'home_y' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | if (mecho_visited[home_x][home_y])
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
mecho.cpp:84:41: warning: 'home_x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6476 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
6476 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
6476 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
6476 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
6476 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
6476 KB |
Output isn't correct |
7 |
Incorrect |
214 ms |
7416 KB |
Output isn't correct |
8 |
Correct |
6 ms |
6476 KB |
Output is correct |
9 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
6532 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
13 |
Correct |
4 ms |
6588 KB |
Output is correct |
14 |
Correct |
5 ms |
6476 KB |
Output is correct |
15 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
6476 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
19 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
20 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
21 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
22 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
23 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
24 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
25 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
26 |
Incorrect |
5 ms |
6476 KB |
Output isn't correct |
27 |
Incorrect |
5 ms |
6588 KB |
Output isn't correct |
28 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
29 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
6604 KB |
Output isn't correct |
31 |
Incorrect |
4 ms |
6592 KB |
Output isn't correct |
32 |
Incorrect |
4 ms |
6476 KB |
Output isn't correct |
33 |
Incorrect |
7 ms |
6748 KB |
Output isn't correct |
34 |
Incorrect |
8 ms |
6748 KB |
Output isn't correct |
35 |
Incorrect |
27 ms |
6732 KB |
Output isn't correct |
36 |
Incorrect |
8 ms |
6732 KB |
Output isn't correct |
37 |
Incorrect |
9 ms |
6732 KB |
Output isn't correct |
38 |
Incorrect |
37 ms |
6752 KB |
Output isn't correct |
39 |
Incorrect |
9 ms |
6792 KB |
Output isn't correct |
40 |
Incorrect |
10 ms |
6796 KB |
Output isn't correct |
41 |
Incorrect |
46 ms |
6732 KB |
Output isn't correct |
42 |
Incorrect |
10 ms |
6988 KB |
Output isn't correct |
43 |
Incorrect |
11 ms |
7004 KB |
Output isn't correct |
44 |
Incorrect |
56 ms |
7008 KB |
Output isn't correct |
45 |
Incorrect |
12 ms |
6988 KB |
Output isn't correct |
46 |
Incorrect |
13 ms |
7116 KB |
Output isn't correct |
47 |
Incorrect |
68 ms |
7092 KB |
Output isn't correct |
48 |
Incorrect |
13 ms |
7116 KB |
Output isn't correct |
49 |
Incorrect |
13 ms |
7140 KB |
Output isn't correct |
50 |
Incorrect |
81 ms |
7136 KB |
Output isn't correct |
51 |
Incorrect |
15 ms |
7088 KB |
Output isn't correct |
52 |
Incorrect |
25 ms |
7160 KB |
Output isn't correct |
53 |
Incorrect |
93 ms |
7204 KB |
Output isn't correct |
54 |
Incorrect |
15 ms |
7244 KB |
Output isn't correct |
55 |
Incorrect |
19 ms |
7212 KB |
Output isn't correct |
56 |
Incorrect |
127 ms |
7244 KB |
Output isn't correct |
57 |
Incorrect |
18 ms |
7244 KB |
Output isn't correct |
58 |
Incorrect |
18 ms |
7292 KB |
Output isn't correct |
59 |
Incorrect |
121 ms |
7244 KB |
Output isn't correct |
60 |
Incorrect |
20 ms |
7244 KB |
Output isn't correct |
61 |
Incorrect |
20 ms |
7244 KB |
Output isn't correct |
62 |
Incorrect |
143 ms |
7236 KB |
Output isn't correct |
63 |
Incorrect |
183 ms |
7340 KB |
Output isn't correct |
64 |
Incorrect |
199 ms |
7336 KB |
Output isn't correct |
65 |
Incorrect |
234 ms |
7336 KB |
Output isn't correct |
66 |
Incorrect |
188 ms |
7244 KB |
Output isn't correct |
67 |
Correct |
231 ms |
7456 KB |
Output is correct |
68 |
Incorrect |
197 ms |
7372 KB |
Output isn't correct |
69 |
Incorrect |
146 ms |
7360 KB |
Output isn't correct |
70 |
Incorrect |
181 ms |
7324 KB |
Output isn't correct |
71 |
Incorrect |
148 ms |
7360 KB |
Output isn't correct |
72 |
Incorrect |
241 ms |
7272 KB |
Output isn't correct |
73 |
Incorrect |
148 ms |
7536 KB |
Output isn't correct |
74 |
Incorrect |
205 ms |
7628 KB |
Output isn't correct |
75 |
Incorrect |
254 ms |
7620 KB |
Output isn't correct |
76 |
Incorrect |
237 ms |
7628 KB |
Output isn't correct |
77 |
Incorrect |
232 ms |
7592 KB |
Output isn't correct |
78 |
Correct |
225 ms |
7564 KB |
Output is correct |
79 |
Incorrect |
204 ms |
7596 KB |
Output isn't correct |
80 |
Incorrect |
262 ms |
7596 KB |
Output isn't correct |
81 |
Incorrect |
234 ms |
7500 KB |
Output isn't correct |
82 |
Incorrect |
251 ms |
7536 KB |
Output isn't correct |
83 |
Incorrect |
242 ms |
7560 KB |
Output isn't correct |
84 |
Incorrect |
208 ms |
7500 KB |
Output isn't correct |
85 |
Incorrect |
240 ms |
7500 KB |
Output isn't correct |
86 |
Incorrect |
251 ms |
7560 KB |
Output isn't correct |
87 |
Incorrect |
233 ms |
7548 KB |
Output isn't correct |
88 |
Incorrect |
223 ms |
7500 KB |
Output isn't correct |
89 |
Incorrect |
233 ms |
7508 KB |
Output isn't correct |
90 |
Incorrect |
215 ms |
7424 KB |
Output isn't correct |
91 |
Incorrect |
231 ms |
7492 KB |
Output isn't correct |
92 |
Incorrect |
249 ms |
7500 KB |
Output isn't correct |