# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
816006 |
2023-08-09T03:40:57 Z |
powervic08 |
Mecho (IOI09_mecho) |
C++17 |
|
158 ms |
6532 KB |
#include <iostream>
#include <vector>
#include <queue>
#define pii pair<int, int>
using namespace std;
int N, S;
int mR, mC, dR, dC;
char grid[801][801];
int minHiveDist[801][801], minBearDist[801][801];
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
bool isValid(int r, int c) { return 0 <= r && r < N && 0 <= c && c < N; }
vector<vector<bool>> visited;
void bfs(vector<pii> initialCoords) {
queue<pair<pii, int>> q;
visited.clear(); visited.resize(N, vector<bool>(N));
for (pii p : initialCoords) {
q.push({ p, 0 }); visited[p.first][p.second] = true;
}
while (!q.empty()) {
pii loc = q.front().first; int dist = q.front().second; q.pop();
minHiveDist[loc.first][loc.second] = dist;
for (int i = 0; i < 4; i++) {
int r = loc.first + dx[i], c = loc.second + dy[i];
if (isValid(r, c) && !visited[r][c] && grid[r][c] != 'T' && grid[r][c] != 'D') {
visited[r][c] = true;
q.push({ {r, c}, dist + 1 });
}
}
}
}
void bfs2(int startR, int startC, int wait) {
visited.clear(); visited.resize(N, vector<bool>(N));
if (minHiveDist[startR][startC] <= wait * S) return;
queue<pair<pii, int>> q; q.push({ {startR, startC}, 0 });
visited[startR][startC] = true;
while (!q.empty()) {
pii loc = q.front().first; int dist = q.front().second; q.pop();
minBearDist[loc.first][loc.second] = dist;
for (int i = 0; i < 4; i++) {
int r = loc.first + dx[i], c = loc.second + dy[i];
if (isValid(r, c) && !visited[r][c] && grid[r][c] != 'T') {
if ((dist + 1) / S + wait < minHiveDist[r][c]) {
visited[r][c] = true;
q.push({ {r, c}, dist + 1 });
}
}
}
}
}
bool works(int wait) {
bfs2(mR, mC, wait);
return visited[dR][dC];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> S;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cin >> grid[i][j];
vector<pii> hives;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (grid[i][j] == 'H') hives.push_back({ i, j });
if (grid[i][j] == 'M') { mR = i; mC = j; }
if (grid[i][j] == 'D') { dR = i; dC = j; }
}
}
bfs(hives); minHiveDist[dR][dC] = (int)1e9;
int low = 0, high = N * N;
while (low < high) {
int mid = (low + high + 1) / 2;
if (works(mid)) low = mid;
else high = mid - 1;
} cout << (works(low) ? low : low - 1) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Incorrect |
34 ms |
5356 KB |
Output isn't correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
21 |
Correct |
0 ms |
468 KB |
Output is correct |
22 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
33 |
Correct |
4 ms |
2004 KB |
Output is correct |
34 |
Incorrect |
9 ms |
2836 KB |
Output isn't correct |
35 |
Incorrect |
6 ms |
2772 KB |
Output isn't correct |
36 |
Correct |
8 ms |
2240 KB |
Output is correct |
37 |
Incorrect |
10 ms |
3156 KB |
Output isn't correct |
38 |
Incorrect |
7 ms |
3204 KB |
Output isn't correct |
39 |
Correct |
8 ms |
2456 KB |
Output is correct |
40 |
Incorrect |
12 ms |
3552 KB |
Output isn't correct |
41 |
Incorrect |
9 ms |
3540 KB |
Output isn't correct |
42 |
Correct |
8 ms |
2740 KB |
Output is correct |
43 |
Incorrect |
27 ms |
3920 KB |
Output isn't correct |
44 |
Incorrect |
11 ms |
3924 KB |
Output isn't correct |
45 |
Correct |
10 ms |
2940 KB |
Output is correct |
46 |
Incorrect |
24 ms |
4272 KB |
Output isn't correct |
47 |
Incorrect |
14 ms |
4256 KB |
Output isn't correct |
48 |
Correct |
11 ms |
3152 KB |
Output is correct |
49 |
Incorrect |
38 ms |
4644 KB |
Output isn't correct |
50 |
Incorrect |
15 ms |
4572 KB |
Output isn't correct |
51 |
Correct |
17 ms |
3384 KB |
Output is correct |
52 |
Incorrect |
26 ms |
4968 KB |
Output isn't correct |
53 |
Incorrect |
18 ms |
4904 KB |
Output isn't correct |
54 |
Correct |
22 ms |
3724 KB |
Output is correct |
55 |
Incorrect |
51 ms |
5360 KB |
Output isn't correct |
56 |
Incorrect |
22 ms |
5292 KB |
Output isn't correct |
57 |
Correct |
24 ms |
3868 KB |
Output is correct |
58 |
Incorrect |
42 ms |
5728 KB |
Output isn't correct |
59 |
Incorrect |
23 ms |
5736 KB |
Output isn't correct |
60 |
Correct |
18 ms |
4128 KB |
Output is correct |
61 |
Incorrect |
49 ms |
6000 KB |
Output isn't correct |
62 |
Incorrect |
27 ms |
6076 KB |
Output isn't correct |
63 |
Correct |
97 ms |
6084 KB |
Output is correct |
64 |
Incorrect |
65 ms |
6016 KB |
Output isn't correct |
65 |
Correct |
158 ms |
6092 KB |
Output is correct |
66 |
Correct |
104 ms |
6068 KB |
Output is correct |
67 |
Correct |
102 ms |
6080 KB |
Output is correct |
68 |
Correct |
46 ms |
6124 KB |
Output is correct |
69 |
Incorrect |
38 ms |
6128 KB |
Output isn't correct |
70 |
Correct |
36 ms |
6060 KB |
Output is correct |
71 |
Correct |
32 ms |
6132 KB |
Output is correct |
72 |
Incorrect |
33 ms |
6052 KB |
Output isn't correct |
73 |
Incorrect |
30 ms |
6476 KB |
Output isn't correct |
74 |
Incorrect |
33 ms |
6440 KB |
Output isn't correct |
75 |
Incorrect |
37 ms |
6484 KB |
Output isn't correct |
76 |
Incorrect |
34 ms |
6532 KB |
Output isn't correct |
77 |
Incorrect |
45 ms |
6532 KB |
Output isn't correct |
78 |
Correct |
81 ms |
5184 KB |
Output is correct |
79 |
Incorrect |
52 ms |
6348 KB |
Output isn't correct |
80 |
Incorrect |
69 ms |
5124 KB |
Output isn't correct |
81 |
Correct |
42 ms |
5016 KB |
Output is correct |
82 |
Incorrect |
43 ms |
5192 KB |
Output isn't correct |
83 |
Correct |
54 ms |
5096 KB |
Output is correct |
84 |
Incorrect |
34 ms |
6348 KB |
Output isn't correct |
85 |
Incorrect |
59 ms |
5140 KB |
Output isn't correct |
86 |
Correct |
69 ms |
5056 KB |
Output is correct |
87 |
Incorrect |
33 ms |
5200 KB |
Output isn't correct |
88 |
Correct |
49 ms |
5204 KB |
Output is correct |
89 |
Incorrect |
34 ms |
6276 KB |
Output isn't correct |
90 |
Incorrect |
50 ms |
5304 KB |
Output isn't correct |
91 |
Incorrect |
37 ms |
6284 KB |
Output isn't correct |
92 |
Correct |
46 ms |
5188 KB |
Output is correct |