# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
749384 |
2023-05-27T20:55:53 Z |
PanosPask |
Mecho (IOI09_mecho) |
C++14 |
|
338 ms |
6804 KB |
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
const int DIRS = 4;
const int d_v[] = {1, 0, -1, 0};
const int d_h[] = {0, 1, 0, -1};
typedef pair<int, int> pi;
int n, steps;
vector<pi> hives;
vector<vector<char>> grid;
vector<vector<int>> bee_distance;
vector<vector<int>> dist;
vector<vector<bool>> vis;
pi dest, mecho;
bool inbound(int coord)
{
return coord >= 0 && coord < n;
}
void calculate_distance(vector<pi>& sources, vector<vector<int>>& dist, bool ismecho, int stepcycle)
{
queue<pi> q;
dist.resize(n);
for (int i = 0; i < n; i++)
dist[i].assign(n, 1e9);
for (int i = 0; i < sources.size(); i++) {
dist[sources[i].f][sources[i].s] = 0;
q.push(sources[i]);
}
while(!q.empty()) {
int i, j;
tie(i, j) = q.front(); q.pop();
for (int x = 0; x < DIRS; x++) {
int ni = i + d_v[x];
int nj = j + d_h[x];
if (inbound(ni) && inbound(nj)
&& (grid[ni][nj] == 'G' || grid[ni][nj] == 'M' || (ismecho && grid[ni][nj] == 'D'))
&& dist[ni][nj] == 1e9) {
dist[ni][nj] = dist[i][j] + stepcycle;
q.push(mp(ni, nj));
}
}
}
}
bool solve_mecho(pi m, int curtime)
{
queue<pi> q;
q.push(m);
dist = bee_distance;
vis.assign(n, vector<bool>(n, false));
dist[m.f][m.s] = curtime;
while (!q.empty()) {
int i, j;
tie(i, j) = q.front(); q.pop();
if (i == dest.f && j == dest.s)
return true;
for (int x = 0; x < 4; x++) {
int ni = i + d_v[x];
int nj = j + d_h[x];
if (inbound(ni) && inbound(nj)
&& dist[ni][nj] >= dist[i][j] + 1
&& (grid[ni][nj] == 'G' || grid[ni][nj] == 'D')
&& !vis[ni][nj]) {
vis[ni][nj] = true;
dist[ni][nj] = dist[i][j] + 1;
q.push(mp(ni, nj));
}
}
}
return false;
}
bool can_reach(int x)
{
return solve_mecho(mecho, x * steps);
}
int main(void)
{
scanf("%d %d", &n, &steps);
grid.resize(n, vector<char>(n));
bee_distance.assign(n, vector<int>(n, 1e9));
vis.assign(n, vector<bool>(n, false));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
scanf(" %c", &grid[i][j]);
if (grid[i][j] == 'H')
hives.push_back(mp(i, j));
else if (grid[i][j] == 'D')
dest = mp(i, j);
else if (grid[i][j] == 'M')
mecho = mp(i, j);
}
calculate_distance(hives, bee_distance, false, steps);
int l = -1;
int r = 1;
while(can_reach(r)) {
l = r;
r *= 2;
}
while (r > l + 1) {
int mid = (l + r) / 2;
if (can_reach(mid))
l = mid;
else
r = mid;
}
int ans = l;
printf("%d\n", ans);
return 0;
}
Compilation message
mecho.cpp: In function 'void calculate_distance(std::vector<std::pair<int, int> >&, std::vector<std::vector<int> >&, bool, int)':
mecho.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < sources.size(); i++) {
| ~~^~~~~~~~~~~~~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | scanf("%d %d", &n, &steps);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
mecho.cpp:107:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf(" %c", &grid[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
128 ms |
6784 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Incorrect |
10 ms |
1464 KB |
Output isn't correct |
34 |
Correct |
10 ms |
1456 KB |
Output is correct |
35 |
Correct |
19 ms |
1492 KB |
Output is correct |
36 |
Incorrect |
12 ms |
1844 KB |
Output isn't correct |
37 |
Correct |
12 ms |
2004 KB |
Output is correct |
38 |
Correct |
25 ms |
1848 KB |
Output is correct |
39 |
Incorrect |
15 ms |
2260 KB |
Output isn't correct |
40 |
Correct |
17 ms |
2336 KB |
Output is correct |
41 |
Correct |
33 ms |
2360 KB |
Output is correct |
42 |
Incorrect |
19 ms |
2760 KB |
Output isn't correct |
43 |
Correct |
19 ms |
2772 KB |
Output is correct |
44 |
Correct |
39 ms |
2756 KB |
Output is correct |
45 |
Incorrect |
23 ms |
3276 KB |
Output isn't correct |
46 |
Correct |
23 ms |
3324 KB |
Output is correct |
47 |
Correct |
45 ms |
3320 KB |
Output is correct |
48 |
Incorrect |
25 ms |
3944 KB |
Output isn't correct |
49 |
Correct |
25 ms |
3916 KB |
Output is correct |
50 |
Correct |
54 ms |
3952 KB |
Output is correct |
51 |
Incorrect |
29 ms |
4528 KB |
Output isn't correct |
52 |
Correct |
29 ms |
4524 KB |
Output is correct |
53 |
Correct |
62 ms |
4524 KB |
Output is correct |
54 |
Incorrect |
36 ms |
5244 KB |
Output isn't correct |
55 |
Correct |
37 ms |
5256 KB |
Output is correct |
56 |
Correct |
73 ms |
5256 KB |
Output is correct |
57 |
Incorrect |
41 ms |
5940 KB |
Output isn't correct |
58 |
Correct |
40 ms |
5964 KB |
Output is correct |
59 |
Correct |
83 ms |
5988 KB |
Output is correct |
60 |
Incorrect |
48 ms |
6656 KB |
Output isn't correct |
61 |
Correct |
47 ms |
6660 KB |
Output is correct |
62 |
Correct |
102 ms |
6768 KB |
Output is correct |
63 |
Correct |
70 ms |
6668 KB |
Output is correct |
64 |
Correct |
338 ms |
6764 KB |
Output is correct |
65 |
Correct |
307 ms |
6764 KB |
Output is correct |
66 |
Incorrect |
234 ms |
6768 KB |
Output isn't correct |
67 |
Correct |
67 ms |
6732 KB |
Output is correct |
68 |
Correct |
60 ms |
6776 KB |
Output is correct |
69 |
Correct |
90 ms |
6692 KB |
Output is correct |
70 |
Correct |
72 ms |
6784 KB |
Output is correct |
71 |
Correct |
65 ms |
6692 KB |
Output is correct |
72 |
Incorrect |
60 ms |
6784 KB |
Output isn't correct |
73 |
Incorrect |
60 ms |
6804 KB |
Output isn't correct |
74 |
Correct |
140 ms |
6692 KB |
Output is correct |
75 |
Correct |
118 ms |
6696 KB |
Output is correct |
76 |
Correct |
100 ms |
6784 KB |
Output is correct |
77 |
Correct |
155 ms |
6800 KB |
Output is correct |
78 |
Correct |
60 ms |
6684 KB |
Output is correct |
79 |
Correct |
135 ms |
6692 KB |
Output is correct |
80 |
Correct |
123 ms |
6668 KB |
Output is correct |
81 |
Correct |
124 ms |
6796 KB |
Output is correct |
82 |
Correct |
121 ms |
6732 KB |
Output is correct |
83 |
Correct |
62 ms |
6784 KB |
Output is correct |
84 |
Correct |
149 ms |
6788 KB |
Output is correct |
85 |
Correct |
121 ms |
6792 KB |
Output is correct |
86 |
Correct |
119 ms |
6800 KB |
Output is correct |
87 |
Correct |
135 ms |
6788 KB |
Output is correct |
88 |
Correct |
59 ms |
6672 KB |
Output is correct |
89 |
Correct |
153 ms |
6788 KB |
Output is correct |
90 |
Correct |
122 ms |
6784 KB |
Output is correct |
91 |
Correct |
141 ms |
6788 KB |
Output is correct |
92 |
Correct |
103 ms |
6736 KB |
Output is correct |