# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
543950 |
2022-03-31T17:02:02 Z |
timreizin |
Mecho (IOI09_mecho) |
C++17 |
|
217 ms |
6268 KB |
#include <iostream>
#include <vector>
#include <array>
#include <numeric>
#include <cassert>
#include <tuple>
#include <queue>
using namespace std;
using ll = long long;
const int INF = 1e9;
const array<int, 4> dx{1, -1, 0, 0}, dy{0, 0, 1, -1};
bool check(int w, int s, vector<string> &forest, vector<vector<int>> &beeD)
{
vector<vector<int>> dist(beeD.size(), vector<int>(beeD.size(), INF));
queue<pair<int, int>> q;
for (int i = 0; i < beeD.size(); ++i)
{
for (int j = 0; j < beeD.size(); ++j)
{
if (forest[i][j] == 'M')
{
if (beeD[i][j] <= w) return false;
dist[i][j] = 0;
q.push({i, j});
}
}
}
while (!q.empty())
{
auto [i, j] = q.front();
q.pop();
for (int k = 0; k < 4; ++k)
{
if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
{
if (dist[i + dx[k]][j + dy[k]] > dist[i][j] + 1 && forest[i + dx[k]][j + dy[k]] != 'T')
{
if ((dist[i][j] + 1) / s + w < beeD[i + dx[k]][j + dy[k]])
{
dist[i + dx[k]][j + dy[k]] = dist[i][j] + 1;
q.push({i + dx[k], j + dy[k]});
}
}
}
}
}
for (int i = 0; i < beeD.size(); ++i) for (int j = 0; j < beeD.size(); ++j) if (forest[i][j] == 'D') return dist[i][j] != INF;
return false;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, s;
cin >> n >> s;
vector<string> forest(n);
for (string &i : forest) cin >> i;
vector<vector<int>> beeD(n, vector<int>(n, INF));
queue<pair<int, int>> q;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (forest[i][j] == 'H')
{
beeD[i][j] = 0;
q.push({i, j});
}
}
}
while (!q.empty())
{
auto [i, j] = q.front();
q.pop();
for (int k = 0; k < 4; ++k)
{
if (i + dx[k] >= 0 && i + dx[k] < n && j + dy[k] >= 0 && j + dy[k] < n)
{
if (beeD[i + dx[k]][j + dy[k]] > beeD[i][j] + 1 && (forest[i + dx[k]][j + dy[k]] == 'G' || forest[i + dx[k]][j + dy[k]] == 'M'))
{
beeD[i + dx[k]][j + dy[k]] = beeD[i][j] + 1;
q.push({i + dx[k], j + dy[k]});
}
}
}
}
int l = 0, r = n * n;
while (l < r)
{
int m = (l + r) >> 1;
if (check(m, s, forest, beeD)) l = m + 1;
else r = m;
}
cout << l - 1;
return 0;
}
Compilation message
mecho.cpp: In function 'bool check(int, int, std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::vector<int> >&)':
mecho.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < beeD.size(); ++i)
| ~~^~~~~~~~~~~~~
mecho.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int j = 0; j < beeD.size(); ++j)
| ~~^~~~~~~~~~~~~
mecho.cpp:39:45: warning: comparison of integer expressions of different signedness: 'std::tuple_element<0, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
| ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:39:90: warning: comparison of integer expressions of different signedness: 'std::tuple_element<1, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
| ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < beeD.size(); ++i) for (int j = 0; j < beeD.size(); ++j) if (forest[i][j] == 'D') return dist[i][j] != INF;
| ~~^~~~~~~~~~~~~
mecho.cpp:52:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < beeD.size(); ++i) for (int j = 0; j < beeD.size(); ++j) if (forest[i][j] == 'D') return dist[i][j] != INF;
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
109 ms |
6124 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
7 ms |
1476 KB |
Output is correct |
34 |
Correct |
10 ms |
1444 KB |
Output is correct |
35 |
Correct |
22 ms |
1436 KB |
Output is correct |
36 |
Correct |
9 ms |
1776 KB |
Output is correct |
37 |
Correct |
13 ms |
1788 KB |
Output is correct |
38 |
Correct |
34 ms |
1820 KB |
Output is correct |
39 |
Correct |
16 ms |
2156 KB |
Output is correct |
40 |
Correct |
15 ms |
2156 KB |
Output is correct |
41 |
Correct |
45 ms |
2164 KB |
Output is correct |
42 |
Correct |
16 ms |
2640 KB |
Output is correct |
43 |
Correct |
18 ms |
2644 KB |
Output is correct |
44 |
Correct |
48 ms |
2640 KB |
Output is correct |
45 |
Correct |
18 ms |
3092 KB |
Output is correct |
46 |
Correct |
21 ms |
3044 KB |
Output is correct |
47 |
Correct |
63 ms |
3164 KB |
Output is correct |
48 |
Correct |
20 ms |
3584 KB |
Output is correct |
49 |
Correct |
26 ms |
3576 KB |
Output is correct |
50 |
Correct |
68 ms |
3616 KB |
Output is correct |
51 |
Correct |
24 ms |
4188 KB |
Output is correct |
52 |
Correct |
36 ms |
4176 KB |
Output is correct |
53 |
Correct |
93 ms |
4168 KB |
Output is correct |
54 |
Correct |
31 ms |
4784 KB |
Output is correct |
55 |
Correct |
44 ms |
4780 KB |
Output is correct |
56 |
Correct |
122 ms |
4768 KB |
Output is correct |
57 |
Correct |
37 ms |
5428 KB |
Output is correct |
58 |
Correct |
43 ms |
5428 KB |
Output is correct |
59 |
Correct |
116 ms |
5556 KB |
Output is correct |
60 |
Correct |
38 ms |
6124 KB |
Output is correct |
61 |
Correct |
49 ms |
6132 KB |
Output is correct |
62 |
Correct |
157 ms |
6120 KB |
Output is correct |
63 |
Correct |
173 ms |
6124 KB |
Output is correct |
64 |
Correct |
217 ms |
6096 KB |
Output is correct |
65 |
Correct |
189 ms |
6096 KB |
Output is correct |
66 |
Correct |
157 ms |
6100 KB |
Output is correct |
67 |
Correct |
169 ms |
6104 KB |
Output is correct |
68 |
Correct |
71 ms |
6268 KB |
Output is correct |
69 |
Correct |
65 ms |
6176 KB |
Output is correct |
70 |
Correct |
58 ms |
6132 KB |
Output is correct |
71 |
Correct |
58 ms |
6148 KB |
Output is correct |
72 |
Correct |
48 ms |
6140 KB |
Output is correct |
73 |
Correct |
38 ms |
6180 KB |
Output is correct |
74 |
Correct |
81 ms |
6120 KB |
Output is correct |
75 |
Correct |
82 ms |
6144 KB |
Output is correct |
76 |
Correct |
69 ms |
6144 KB |
Output is correct |
77 |
Correct |
77 ms |
6148 KB |
Output is correct |
78 |
Correct |
94 ms |
6164 KB |
Output is correct |
79 |
Correct |
72 ms |
6220 KB |
Output is correct |
80 |
Correct |
92 ms |
6148 KB |
Output is correct |
81 |
Correct |
108 ms |
6140 KB |
Output is correct |
82 |
Correct |
85 ms |
6128 KB |
Output is correct |
83 |
Correct |
92 ms |
6152 KB |
Output is correct |
84 |
Correct |
87 ms |
6136 KB |
Output is correct |
85 |
Correct |
112 ms |
6144 KB |
Output is correct |
86 |
Correct |
86 ms |
6144 KB |
Output is correct |
87 |
Correct |
87 ms |
6152 KB |
Output is correct |
88 |
Correct |
109 ms |
6156 KB |
Output is correct |
89 |
Correct |
102 ms |
6104 KB |
Output is correct |
90 |
Correct |
101 ms |
6144 KB |
Output is correct |
91 |
Correct |
105 ms |
6196 KB |
Output is correct |
92 |
Correct |
85 ms |
6140 KB |
Output is correct |