# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
391380 |
2021-04-18T16:38:13 Z |
ml1234 |
Mecho (IOI09_mecho) |
C++17 |
|
1000 ms |
6764 KB |
#include <iostream>
#include <string>
#include <queue>
using namespace std;
void floodfillbees(int i, int j);
bool validmecho(int i, int j);
string grid[800];
int bees[800][800];
int dx[] = {0, -1, 1, 0}, dy[] = {-1, 0, 0, 1};
int n, s;
int main()
{
cin >> n >> s;
pair<int, int> mecho = {0, 0};
int mechodist[800][800];
for (int i = 0; i < n; i++)
{
cin >> grid[i];
for (int j = 0; j < n; j++)
{
if (grid[i][j] == 'M')
{
mecho = {i, j};
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
bees[i][j] = 1e9;
mechodist[i][j] = -1;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (grid[i][j] == 'H')
{
floodfillbees(i, j);
}
}
}
queue<pair<pair<int, int>, int>> q; //((i, j, min time difference along path)
q.push({mecho, bees[mecho.first][mecho.second]});
mechodist[mecho.first][mecho.second] = 0;
int ans = 0;
while (!q.empty())
{
int curri = q.front().first.first, currj = q.front().first.second;
int mindiff = q.front().second;
q.pop();
if (grid[curri][currj] == 'D')
{
if (mindiff > 0)
{
ans = max(ans, mindiff / s);
}
continue;
}
for (int d = 0; d < 4; d++)
{
int nexti = curri + dx[d], nextj = currj + dy[d];
if (!validmecho(nexti, nextj))
{
continue;
}
if (mechodist[nexti][nextj] == -1)
{
mechodist[nexti][nextj] = mechodist[curri][currj] + 1;
q.push({{nexti, nextj}, min(mindiff, bees[nexti][nextj] - mechodist[nexti][nextj])});
}
}
}
cout << ans << endl;
return 0;
}
bool ongrid(int i, int j)
{
return (i >= 0 && i < n && j >= 0 && j < n);
}
bool validbees(int i, int j)
{
return (ongrid(i, j) && !(grid[i][j] == 'T') && !(grid[i][j] == 'D') && !(grid[i][j] == 'H'));
}
bool validmecho(int i, int j)
{
return (ongrid(i, j) && !(grid[i][j] == 'T'));
}
void floodfillbees(int i, int j)
{
queue<pair<int, int>> q;
q.push({i, j});
bees[i][j] = 0;
while (!q.empty())
{
int curri = q.front().first, currj = q.front().second;
q.pop();
for (int d = 0; d < 4; d++)
{
int nexti = curri + dx[d], nextj = currj + dy[d];
if (validbees(nexti, nextj) && bees[nexti][nextj] > bees[curri][currj] + s)
{
bees[nexti][nextj] = bees[curri][currj] + s;
q.push({nexti, nextj});
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
275 ms |
6724 KB |
Output is correct |
8 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
24 |
Correct |
1 ms |
588 KB |
Output is correct |
25 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
26 |
Correct |
1 ms |
716 KB |
Output is correct |
27 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
30 |
Correct |
1 ms |
716 KB |
Output is correct |
31 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
32 |
Correct |
1 ms |
716 KB |
Output is correct |
33 |
Incorrect |
9 ms |
2824 KB |
Output isn't correct |
34 |
Correct |
10 ms |
2764 KB |
Output is correct |
35 |
Incorrect |
18 ms |
2824 KB |
Output isn't correct |
36 |
Incorrect |
14 ms |
3148 KB |
Output isn't correct |
37 |
Correct |
12 ms |
3192 KB |
Output is correct |
38 |
Incorrect |
18 ms |
3196 KB |
Output isn't correct |
39 |
Incorrect |
15 ms |
3532 KB |
Output isn't correct |
40 |
Correct |
15 ms |
3512 KB |
Output is correct |
41 |
Incorrect |
24 ms |
3532 KB |
Output isn't correct |
42 |
Incorrect |
16 ms |
4172 KB |
Output isn't correct |
43 |
Correct |
20 ms |
4192 KB |
Output is correct |
44 |
Incorrect |
28 ms |
4172 KB |
Output isn't correct |
45 |
Incorrect |
20 ms |
4556 KB |
Output isn't correct |
46 |
Correct |
28 ms |
4568 KB |
Output is correct |
47 |
Incorrect |
34 ms |
4596 KB |
Output isn't correct |
48 |
Incorrect |
24 ms |
5020 KB |
Output isn't correct |
49 |
Correct |
28 ms |
4940 KB |
Output is correct |
50 |
Incorrect |
39 ms |
4940 KB |
Output isn't correct |
51 |
Incorrect |
27 ms |
5436 KB |
Output isn't correct |
52 |
Correct |
30 ms |
5324 KB |
Output is correct |
53 |
Incorrect |
46 ms |
5444 KB |
Output isn't correct |
54 |
Incorrect |
31 ms |
5836 KB |
Output isn't correct |
55 |
Correct |
35 ms |
5860 KB |
Output is correct |
56 |
Incorrect |
57 ms |
5836 KB |
Output isn't correct |
57 |
Incorrect |
35 ms |
6304 KB |
Output isn't correct |
58 |
Correct |
39 ms |
6220 KB |
Output is correct |
59 |
Incorrect |
63 ms |
6220 KB |
Output isn't correct |
60 |
Incorrect |
41 ms |
6604 KB |
Output isn't correct |
61 |
Correct |
45 ms |
6724 KB |
Output is correct |
62 |
Incorrect |
70 ms |
6724 KB |
Output isn't correct |
63 |
Correct |
120 ms |
6596 KB |
Output is correct |
64 |
Correct |
107 ms |
6716 KB |
Output is correct |
65 |
Correct |
109 ms |
6732 KB |
Output is correct |
66 |
Incorrect |
128 ms |
6720 KB |
Output isn't correct |
67 |
Incorrect |
121 ms |
6724 KB |
Output isn't correct |
68 |
Correct |
300 ms |
6708 KB |
Output is correct |
69 |
Correct |
309 ms |
6604 KB |
Output is correct |
70 |
Correct |
300 ms |
6764 KB |
Output is correct |
71 |
Correct |
323 ms |
6712 KB |
Output is correct |
72 |
Incorrect |
298 ms |
6728 KB |
Output isn't correct |
73 |
Execution timed out |
1093 ms |
6604 KB |
Time limit exceeded |
74 |
Execution timed out |
1081 ms |
6732 KB |
Time limit exceeded |
75 |
Execution timed out |
1074 ms |
6596 KB |
Time limit exceeded |
76 |
Execution timed out |
1094 ms |
6604 KB |
Time limit exceeded |
77 |
Execution timed out |
1057 ms |
6604 KB |
Time limit exceeded |
78 |
Execution timed out |
1047 ms |
6604 KB |
Time limit exceeded |
79 |
Execution timed out |
1061 ms |
6700 KB |
Time limit exceeded |
80 |
Execution timed out |
1088 ms |
6596 KB |
Time limit exceeded |
81 |
Execution timed out |
1076 ms |
6604 KB |
Time limit exceeded |
82 |
Execution timed out |
1093 ms |
6660 KB |
Time limit exceeded |
83 |
Correct |
511 ms |
6716 KB |
Output is correct |
84 |
Correct |
462 ms |
6720 KB |
Output is correct |
85 |
Correct |
443 ms |
6712 KB |
Output is correct |
86 |
Incorrect |
451 ms |
6720 KB |
Output isn't correct |
87 |
Correct |
456 ms |
6724 KB |
Output is correct |
88 |
Correct |
432 ms |
6716 KB |
Output is correct |
89 |
Correct |
363 ms |
6712 KB |
Output is correct |
90 |
Correct |
380 ms |
6716 KB |
Output is correct |
91 |
Correct |
352 ms |
6708 KB |
Output is correct |
92 |
Correct |
348 ms |
6732 KB |
Output is correct |