# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
543880 |
2022-03-31T14:27:49 Z |
timreizin |
Mecho (IOI09_mecho) |
C++17 |
|
232 ms |
6264 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')
{
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')
{
beeD[i + dx[k]][j + dy[k]] = beeD[i][j] + 1;
q.push({i + dx[k], j + dy[k]});
}
}
}
}
if (!check(0, s, forest, beeD))
{
cout << -1;
return 0;
}
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;
}
/*
7 3
TTTTTTT
TGGGGGT
TGGGGGT
MGGGGGD
TGGGGGT
TGGGGGT
TGHHGGT
*/
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:38: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]
38 | if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
| ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:38: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]
38 | if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
| ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | 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:51:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | 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 |
1 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
117 ms |
6164 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 |
0 ms |
212 KB |
Output is correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
0 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 |
1 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 |
9 ms |
1432 KB |
Output is correct |
34 |
Correct |
10 ms |
1436 KB |
Output is correct |
35 |
Correct |
28 ms |
1500 KB |
Output is correct |
36 |
Correct |
11 ms |
1748 KB |
Output is correct |
37 |
Correct |
13 ms |
1748 KB |
Output is correct |
38 |
Correct |
35 ms |
1748 KB |
Output is correct |
39 |
Correct |
14 ms |
2156 KB |
Output is correct |
40 |
Correct |
17 ms |
2220 KB |
Output is correct |
41 |
Correct |
45 ms |
2204 KB |
Output is correct |
42 |
Correct |
17 ms |
2588 KB |
Output is correct |
43 |
Correct |
23 ms |
2648 KB |
Output is correct |
44 |
Correct |
60 ms |
2584 KB |
Output is correct |
45 |
Correct |
26 ms |
3056 KB |
Output is correct |
46 |
Correct |
25 ms |
3044 KB |
Output is correct |
47 |
Correct |
71 ms |
3044 KB |
Output is correct |
48 |
Correct |
27 ms |
3624 KB |
Output is correct |
49 |
Correct |
31 ms |
3624 KB |
Output is correct |
50 |
Correct |
76 ms |
3600 KB |
Output is correct |
51 |
Correct |
31 ms |
4180 KB |
Output is correct |
52 |
Correct |
36 ms |
4128 KB |
Output is correct |
53 |
Correct |
95 ms |
4164 KB |
Output is correct |
54 |
Correct |
39 ms |
4780 KB |
Output is correct |
55 |
Correct |
42 ms |
4776 KB |
Output is correct |
56 |
Correct |
115 ms |
4808 KB |
Output is correct |
57 |
Correct |
41 ms |
5464 KB |
Output is correct |
58 |
Correct |
50 ms |
5424 KB |
Output is correct |
59 |
Correct |
128 ms |
5412 KB |
Output is correct |
60 |
Correct |
47 ms |
6148 KB |
Output is correct |
61 |
Correct |
56 ms |
6192 KB |
Output is correct |
62 |
Correct |
164 ms |
6096 KB |
Output is correct |
63 |
Correct |
150 ms |
6096 KB |
Output is correct |
64 |
Correct |
211 ms |
6084 KB |
Output is correct |
65 |
Correct |
232 ms |
6100 KB |
Output is correct |
66 |
Correct |
162 ms |
6156 KB |
Output is correct |
67 |
Correct |
30 ms |
5992 KB |
Output is correct |
68 |
Correct |
81 ms |
6124 KB |
Output is correct |
69 |
Correct |
72 ms |
6128 KB |
Output is correct |
70 |
Correct |
68 ms |
6264 KB |
Output is correct |
71 |
Correct |
61 ms |
6208 KB |
Output is correct |
72 |
Incorrect |
68 ms |
6116 KB |
Output isn't correct |
73 |
Incorrect |
95 ms |
6188 KB |
Output isn't correct |
74 |
Correct |
96 ms |
6100 KB |
Output is correct |
75 |
Correct |
96 ms |
6132 KB |
Output is correct |
76 |
Correct |
86 ms |
6128 KB |
Output is correct |
77 |
Correct |
94 ms |
6152 KB |
Output is correct |
78 |
Correct |
26 ms |
6100 KB |
Output is correct |
79 |
Correct |
83 ms |
6208 KB |
Output is correct |
80 |
Correct |
85 ms |
6124 KB |
Output is correct |
81 |
Correct |
102 ms |
6128 KB |
Output is correct |
82 |
Correct |
88 ms |
6144 KB |
Output is correct |
83 |
Correct |
105 ms |
6196 KB |
Output is correct |
84 |
Correct |
98 ms |
6124 KB |
Output is correct |
85 |
Correct |
95 ms |
6128 KB |
Output is correct |
86 |
Correct |
102 ms |
6132 KB |
Output is correct |
87 |
Correct |
101 ms |
6144 KB |
Output is correct |
88 |
Correct |
111 ms |
6144 KB |
Output is correct |
89 |
Correct |
112 ms |
6128 KB |
Output is correct |
90 |
Correct |
109 ms |
6120 KB |
Output is correct |
91 |
Correct |
121 ms |
6232 KB |
Output is correct |
92 |
Correct |
100 ms |
6192 KB |
Output is correct |