# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1037097 |
2024-07-28T04:16:05 Z |
sssamui |
Mecho (IOI09_mecho) |
C++17 |
|
367 ms |
4184 KB |
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
vector<vector<char>> grd(802, vector<char>(802, 'T'));
vector<vector<bool>> swm(802, vector<bool>(802, false));
vector<vector<int>> btime(802, vector<int>(802, 1e8));
int sttr, sttc;
int dstr, dstc;
int h, s;
vector<int> radd = { -1, 0, 1, 0 };
vector<int> cadd = { 0, -1, 0, 1 };
bool check(int tchk)
{
queue<pair<int, pair<int, int>>> bfs;
bfs.push({ 0, {sttr, sttc} });
vector<vector<bool>> poss(h + 2, vector<bool>(h + 2, false));
poss[sttr][sttc] = true;
while (!bfs.empty() && !poss[dstr][dstc])
{
int r = bfs.front().second.first, c = bfs.front().second.second, dst = bfs.front().first;
bfs.pop();
for (int dir = 0; dir < 4; dir++) if (!poss[r + radd[dir]][c + cadd[dir]]) if (grd[r + radd[dir]][c + cadd[dir]] == 'G')
if ((dst + 1) / s < btime[r + radd[dir]][c + cadd[dir]] - tchk)
{
poss[r + radd[dir]][c + cadd[dir]] = true;
bfs.push({ dst + 1, {r + radd[dir], c + cadd[dir]} });
}
}
return poss[dstr][dstc];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> h >> s;
queue<pair<int, int>> swmpcs;
for (int i = 1; i <= h; i++) for (int j = 1; j <= h; j++)
{
cin >> grd[i][j];
if (grd[i][j] == 'M')
{
sttr = i;
sttc = j;
grd[i][j] = 'G';
}
else if (grd[i][j] == 'D')
{
dstr = i;
dstc = j;
grd[i][j] = 'T';
}
else if (grd[i][j] == 'H')
{
swmpcs.push({ i, j });
swm[i][j] = true;
grd[i][j] = 'T';
}
}
while (!swmpcs.empty())
{
int r = swmpcs.front().first, c = swmpcs.front().second;
swmpcs.pop();
for (int dir = 0; dir < 4; dir++) if ((!swm[r + radd[dir]][c + cadd[dir]]) && (grd[r + radd[dir]][c + cadd[dir]] == 'G'))
{
swm[r + radd[dir]][c + cadd[dir]] = true;
btime[r + radd[dir]][c + cadd[dir]] = btime[r][c] + 1;
swmpcs.push({ r + radd[dir], c + cadd[dir] });
}
}
btime[dstr][dstc] = btime[sttr][sttc];
grd[dstr][dstc] = 'G';
if (!check(0)) cout << -1;
else
{
int l = 0, r = btime[sttr][sttc] - 1;
while (l < r)
{
int mid = l + (r - l + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
7 |
Incorrect |
195 ms |
3784 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
3672 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
14 |
Incorrect |
4 ms |
3676 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
3552 KB |
Output isn't correct |
17 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
3772 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
3672 KB |
Output isn't correct |
21 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
23 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
24 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
26 |
Incorrect |
3 ms |
3764 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
30 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
32 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
34 |
Incorrect |
6 ms |
3676 KB |
Output isn't correct |
35 |
Incorrect |
36 ms |
3776 KB |
Output isn't correct |
36 |
Incorrect |
6 ms |
3672 KB |
Output isn't correct |
37 |
Incorrect |
6 ms |
3676 KB |
Output isn't correct |
38 |
Incorrect |
41 ms |
3676 KB |
Output isn't correct |
39 |
Incorrect |
6 ms |
3676 KB |
Output isn't correct |
40 |
Incorrect |
6 ms |
3676 KB |
Output isn't correct |
41 |
Incorrect |
53 ms |
3820 KB |
Output isn't correct |
42 |
Incorrect |
8 ms |
3672 KB |
Output isn't correct |
43 |
Incorrect |
9 ms |
3676 KB |
Output isn't correct |
44 |
Incorrect |
66 ms |
3844 KB |
Output isn't correct |
45 |
Incorrect |
10 ms |
3676 KB |
Output isn't correct |
46 |
Incorrect |
9 ms |
3784 KB |
Output isn't correct |
47 |
Incorrect |
94 ms |
3672 KB |
Output isn't correct |
48 |
Incorrect |
10 ms |
3672 KB |
Output isn't correct |
49 |
Incorrect |
10 ms |
3676 KB |
Output isn't correct |
50 |
Incorrect |
94 ms |
3848 KB |
Output isn't correct |
51 |
Incorrect |
10 ms |
3672 KB |
Output isn't correct |
52 |
Incorrect |
11 ms |
3676 KB |
Output isn't correct |
53 |
Incorrect |
110 ms |
3852 KB |
Output isn't correct |
54 |
Incorrect |
13 ms |
3676 KB |
Output isn't correct |
55 |
Incorrect |
18 ms |
3784 KB |
Output isn't correct |
56 |
Incorrect |
125 ms |
3792 KB |
Output isn't correct |
57 |
Incorrect |
14 ms |
3676 KB |
Output isn't correct |
58 |
Incorrect |
16 ms |
3776 KB |
Output isn't correct |
59 |
Incorrect |
144 ms |
3676 KB |
Output isn't correct |
60 |
Incorrect |
16 ms |
3676 KB |
Output isn't correct |
61 |
Incorrect |
16 ms |
3788 KB |
Output isn't correct |
62 |
Incorrect |
167 ms |
3672 KB |
Output isn't correct |
63 |
Incorrect |
320 ms |
3676 KB |
Output isn't correct |
64 |
Incorrect |
367 ms |
3884 KB |
Output isn't correct |
65 |
Incorrect |
334 ms |
3880 KB |
Output isn't correct |
66 |
Incorrect |
332 ms |
3672 KB |
Output isn't correct |
67 |
Incorrect |
320 ms |
3884 KB |
Output isn't correct |
68 |
Incorrect |
294 ms |
3672 KB |
Output isn't correct |
69 |
Incorrect |
299 ms |
3804 KB |
Output isn't correct |
70 |
Incorrect |
283 ms |
3672 KB |
Output isn't correct |
71 |
Incorrect |
287 ms |
3672 KB |
Output isn't correct |
72 |
Incorrect |
37 ms |
3676 KB |
Output isn't correct |
73 |
Incorrect |
213 ms |
3932 KB |
Output isn't correct |
74 |
Incorrect |
170 ms |
3928 KB |
Output isn't correct |
75 |
Incorrect |
171 ms |
4036 KB |
Output isn't correct |
76 |
Incorrect |
163 ms |
3928 KB |
Output isn't correct |
77 |
Incorrect |
171 ms |
3928 KB |
Output isn't correct |
78 |
Incorrect |
198 ms |
3928 KB |
Output isn't correct |
79 |
Incorrect |
183 ms |
3932 KB |
Output isn't correct |
80 |
Incorrect |
176 ms |
3932 KB |
Output isn't correct |
81 |
Incorrect |
177 ms |
4184 KB |
Output isn't correct |
82 |
Incorrect |
174 ms |
3928 KB |
Output isn't correct |
83 |
Incorrect |
202 ms |
3928 KB |
Output isn't correct |
84 |
Incorrect |
188 ms |
3968 KB |
Output isn't correct |
85 |
Incorrect |
200 ms |
3972 KB |
Output isn't correct |
86 |
Incorrect |
194 ms |
3932 KB |
Output isn't correct |
87 |
Incorrect |
193 ms |
3988 KB |
Output isn't correct |
88 |
Incorrect |
202 ms |
3928 KB |
Output isn't correct |
89 |
Incorrect |
212 ms |
3932 KB |
Output isn't correct |
90 |
Incorrect |
211 ms |
3928 KB |
Output isn't correct |
91 |
Incorrect |
226 ms |
3932 KB |
Output isn't correct |
92 |
Incorrect |
211 ms |
3928 KB |
Output isn't correct |