# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
401055 |
2021-05-09T09:32:16 Z |
ruadhan |
Mecho (IOI09_mecho) |
C++17 |
|
299 ms |
6436 KB |
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define x first
#define y second
#define X 0
#define Y 1
#define TIME 2
#define STEPS 3
using namespace std;
typedef pair<int, int> pi;
const int MX = 805;
string grid[MX];
int bees_time[MX][MX];
int N, S;
vector<pi> hives;
vector<pi> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void calc_bee_times()
{
queue<pi> q;
for (auto i : hives)
{
q.push(i);
bees_time[i.x][i.y] = 0;
}
while (!q.empty())
{
auto curr = q.front();
q.pop();
for (auto d : dirs)
{
int i = curr.x + d.x, j = curr.y + d.y;
if (i < 0 || i >= N || j < 0 || j >= N || grid[i][j] == 'T' || grid[i][j] == 'D' || bees_time[i][j] != -1)
continue;
bees_time[i][j] = bees_time[curr.x][curr.y] + 1;
q.push({i, j});
}
}
}
pi mecho, home;
int processed[MX][MX];
bool ok(int t)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
processed[i][j] = -1;
}
if (bees_time[mecho.x][mecho.y] <= t)
return false;
queue<pi> q;
processed[mecho.x][mecho.y] = 0;
q.push(mecho);
while (!q.empty())
{
auto curr = q.front();
// cout << "new queue top = " << curr.x << " " << curr.y << ", d=" << processed[curr.x][curr.y] << '\n';
q.pop();
for (auto d : dirs)
{
int i = curr.x + d.x, j = curr.y + d.y;
if (i < 0 || i >= N || j < 0 || j >= N || grid[i][j] == 'T' || (bees_time[i][j] <= t + (processed[curr.x][curr.y] + 1) / S && make_pair(i, j) != home) || processed[i][j] != -1)
continue;
// cout << "we can go to " << i << ", " << j << " from here with steps = " << processed[curr.x][curr.y] + 1 << ", moves = " << (processed[curr.x][curr.y] + 1) / S << '\n';
processed[i][j] = processed[curr.x][curr.y] + 1;
q.push({i, j});
}
}
return processed[home.x][home.y] != -1;
}
int main()
{
cin >> N >> S;
for (int i = 0; i < MX; i++)
for (int j = 0; j < MX; j++)
bees_time[i][j] = -1;
for (int i = 0; i < N; i++)
{
cin >> grid[i];
for (int j = 0; j < N; j++)
{
if (grid[i][j] == 'H')
hives.push_back({i, j});
else if (grid[i][j] == 'M')
mecho.x = i, mecho.y = j;
else if (grid[i][j] == 'D')
home.x = i, home.y = j;
}
}
calc_bee_times();
// cout << ok(2) << '\n';
// for (int i = 0; i < N; i++)
// {
// for (int j = 0; j < N; j++)
// cout << bees_time[i][j] << " ";
// cout << '\n';
// }
int lo = 0, hi = 800 * 800;
for (int b = hi / 2; b >= 1; b /= 2)
{
while (lo + b < hi && ok(lo + b))
lo += b;
}
if (lo == 0 && !ok(0))
cout << -1 << '\n';
else
cout << lo << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2764 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2764 KB |
Output is correct |
4 |
Correct |
2 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
153 ms |
6272 KB |
Output is correct |
8 |
Correct |
2 ms |
2892 KB |
Output is correct |
9 |
Correct |
2 ms |
2892 KB |
Output is correct |
10 |
Correct |
2 ms |
2892 KB |
Output is correct |
11 |
Correct |
2 ms |
2892 KB |
Output is correct |
12 |
Correct |
2 ms |
2944 KB |
Output is correct |
13 |
Correct |
2 ms |
3020 KB |
Output is correct |
14 |
Correct |
3 ms |
3020 KB |
Output is correct |
15 |
Correct |
2 ms |
2892 KB |
Output is correct |
16 |
Correct |
2 ms |
2892 KB |
Output is correct |
17 |
Correct |
2 ms |
2892 KB |
Output is correct |
18 |
Correct |
2 ms |
2892 KB |
Output is correct |
19 |
Correct |
2 ms |
2892 KB |
Output is correct |
20 |
Correct |
2 ms |
2892 KB |
Output is correct |
21 |
Correct |
2 ms |
2892 KB |
Output is correct |
22 |
Correct |
2 ms |
2892 KB |
Output is correct |
23 |
Correct |
2 ms |
3020 KB |
Output is correct |
24 |
Correct |
2 ms |
3020 KB |
Output is correct |
25 |
Correct |
3 ms |
3020 KB |
Output is correct |
26 |
Correct |
2 ms |
3020 KB |
Output is correct |
27 |
Correct |
3 ms |
3020 KB |
Output is correct |
28 |
Correct |
3 ms |
3020 KB |
Output is correct |
29 |
Correct |
3 ms |
3020 KB |
Output is correct |
30 |
Correct |
3 ms |
3020 KB |
Output is correct |
31 |
Correct |
3 ms |
3020 KB |
Output is correct |
32 |
Correct |
3 ms |
3020 KB |
Output is correct |
33 |
Correct |
10 ms |
4044 KB |
Output is correct |
34 |
Correct |
9 ms |
4044 KB |
Output is correct |
35 |
Correct |
36 ms |
4172 KB |
Output is correct |
36 |
Correct |
13 ms |
4320 KB |
Output is correct |
37 |
Correct |
13 ms |
4300 KB |
Output is correct |
38 |
Correct |
44 ms |
4300 KB |
Output is correct |
39 |
Correct |
14 ms |
4472 KB |
Output is correct |
40 |
Correct |
15 ms |
4492 KB |
Output is correct |
41 |
Correct |
55 ms |
4412 KB |
Output is correct |
42 |
Correct |
17 ms |
4812 KB |
Output is correct |
43 |
Correct |
18 ms |
4912 KB |
Output is correct |
44 |
Correct |
69 ms |
4908 KB |
Output is correct |
45 |
Correct |
25 ms |
5068 KB |
Output is correct |
46 |
Correct |
22 ms |
5060 KB |
Output is correct |
47 |
Correct |
89 ms |
5068 KB |
Output is correct |
48 |
Correct |
26 ms |
5232 KB |
Output is correct |
49 |
Correct |
22 ms |
5224 KB |
Output is correct |
50 |
Correct |
98 ms |
5324 KB |
Output is correct |
51 |
Correct |
26 ms |
5452 KB |
Output is correct |
52 |
Correct |
27 ms |
5532 KB |
Output is correct |
53 |
Correct |
128 ms |
5516 KB |
Output is correct |
54 |
Correct |
30 ms |
5700 KB |
Output is correct |
55 |
Correct |
30 ms |
5732 KB |
Output is correct |
56 |
Correct |
141 ms |
5708 KB |
Output is correct |
57 |
Correct |
33 ms |
5996 KB |
Output is correct |
58 |
Correct |
37 ms |
5812 KB |
Output is correct |
59 |
Correct |
166 ms |
5944 KB |
Output is correct |
60 |
Correct |
43 ms |
6084 KB |
Output is correct |
61 |
Correct |
45 ms |
6044 KB |
Output is correct |
62 |
Correct |
185 ms |
6016 KB |
Output is correct |
63 |
Correct |
134 ms |
6132 KB |
Output is correct |
64 |
Correct |
299 ms |
6136 KB |
Output is correct |
65 |
Correct |
201 ms |
6128 KB |
Output is correct |
66 |
Correct |
186 ms |
6132 KB |
Output is correct |
67 |
Correct |
150 ms |
6256 KB |
Output is correct |
68 |
Correct |
89 ms |
6084 KB |
Output is correct |
69 |
Correct |
86 ms |
6096 KB |
Output is correct |
70 |
Correct |
54 ms |
6084 KB |
Output is correct |
71 |
Correct |
57 ms |
6072 KB |
Output is correct |
72 |
Correct |
62 ms |
6064 KB |
Output is correct |
73 |
Correct |
66 ms |
6340 KB |
Output is correct |
74 |
Correct |
95 ms |
6436 KB |
Output is correct |
75 |
Correct |
121 ms |
6340 KB |
Output is correct |
76 |
Correct |
108 ms |
6340 KB |
Output is correct |
77 |
Correct |
121 ms |
6404 KB |
Output is correct |
78 |
Correct |
118 ms |
6436 KB |
Output is correct |
79 |
Correct |
82 ms |
6340 KB |
Output is correct |
80 |
Correct |
108 ms |
6404 KB |
Output is correct |
81 |
Correct |
122 ms |
6304 KB |
Output is correct |
82 |
Correct |
102 ms |
6404 KB |
Output is correct |
83 |
Correct |
131 ms |
6360 KB |
Output is correct |
84 |
Correct |
140 ms |
6276 KB |
Output is correct |
85 |
Correct |
161 ms |
6252 KB |
Output is correct |
86 |
Correct |
127 ms |
6264 KB |
Output is correct |
87 |
Correct |
153 ms |
6356 KB |
Output is correct |
88 |
Correct |
129 ms |
6284 KB |
Output is correct |
89 |
Correct |
143 ms |
6244 KB |
Output is correct |
90 |
Correct |
140 ms |
6212 KB |
Output is correct |
91 |
Correct |
169 ms |
6340 KB |
Output is correct |
92 |
Correct |
141 ms |
6300 KB |
Output is correct |