# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
470714 |
2021-09-05T08:03:49 Z |
dooompy |
Mecho (IOI09_mecho) |
C++17 |
|
212 ms |
5504 KB |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
bool tree[1005][1005];
int bees[1005][1005];
bool seen[1005][1005];
int n, s, sx, sy, dx, dy;
int mx[]{1, -1, 0, 0};
int my[]{0, 0, 1, -1};
struct bear {
int x, y, time, move;
};
bool able(int time) {
fill(&seen[0][0], &seen[0][0] + sizeof(seen) / sizeof(seen[0][0]), false);
int curtime = time;
// curtime can go into curtime+2 but must finish on curtime+3
queue<bear> q;
q.push({sx, sy, curtime+2, 0});
// seen[sx][sy] = true;
if (bees[sx][sy] < curtime + 2) return false;
while (!q.empty()) {
auto cur = q.front(); q.pop();
if (cur.x == dx && cur.y == dy) return true;
if (seen[cur.x][cur.y]) continue;
if (cur.move == s) {
cur.time++;
if (bees[cur.x][cur.y] < cur.time) {
continue;
}
cur.move = 0;
}
if (bees[cur.x][cur.y] < cur.time) {
continue;
}
seen[cur.x][cur.y] = true;
for (int i = 0; i < 4; i++) {
int newx = cur.x + mx[i], newy = cur.y + my[i];
if (newx < 0 || newx >= n || newy < 0 || newy >= n || ((newx != dx && newy != dy) && bees[newx][newy] < cur.time) || tree[newx][newy] || seen[newx][newy]) continue;
q.push({newx, newy, cur.time, cur.move+1});
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
cin >> n >> s;
queue<pair<int, int>> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char c; cin>> c;
if (c == 'T') tree[i][j] = true;
if (c == 'M') {
sx = i; sy = j;
}
if (c == 'D') {
dx = i; dy = j;
}
if (c == 'H') {
q.push({i, j});
bees[i][j] = 1;
}
}
}
while (!q.empty()) {
auto cur = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int newx = cur.first + mx[i], newy = cur.second + my[i];
if (newx < 0 || newx >= n || newy < 0 || newy >= n || bees[newx][newy] || tree[newx][newy]) continue;
bees[newx][newy] = bees[cur.first][cur.second] + 1;
q.push({newx, newy});
}
}
int lo = 0, hi = 1e9;
int biggest = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (able(mid)) {
biggest = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
cout << biggest;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
2 ms |
1228 KB |
Output is correct |
5 |
Correct |
2 ms |
1228 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
145 ms |
5224 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
2 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1356 KB |
Output is correct |
12 |
Incorrect |
2 ms |
1484 KB |
Output isn't correct |
13 |
Correct |
2 ms |
1484 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
2 ms |
1356 KB |
Output is correct |
17 |
Correct |
2 ms |
1356 KB |
Output is correct |
18 |
Correct |
2 ms |
1356 KB |
Output is correct |
19 |
Correct |
2 ms |
1356 KB |
Output is correct |
20 |
Correct |
2 ms |
1356 KB |
Output is correct |
21 |
Correct |
3 ms |
1484 KB |
Output is correct |
22 |
Correct |
2 ms |
1484 KB |
Output is correct |
23 |
Correct |
2 ms |
1484 KB |
Output is correct |
24 |
Correct |
2 ms |
1484 KB |
Output is correct |
25 |
Correct |
2 ms |
1484 KB |
Output is correct |
26 |
Correct |
2 ms |
1484 KB |
Output is correct |
27 |
Correct |
3 ms |
1612 KB |
Output is correct |
28 |
Correct |
2 ms |
1612 KB |
Output is correct |
29 |
Correct |
3 ms |
1612 KB |
Output is correct |
30 |
Correct |
3 ms |
1612 KB |
Output is correct |
31 |
Correct |
3 ms |
1612 KB |
Output is correct |
32 |
Correct |
2 ms |
1612 KB |
Output is correct |
33 |
Correct |
6 ms |
2984 KB |
Output is correct |
34 |
Correct |
7 ms |
3020 KB |
Output is correct |
35 |
Correct |
34 ms |
2956 KB |
Output is correct |
36 |
Correct |
8 ms |
3276 KB |
Output is correct |
37 |
Correct |
8 ms |
3276 KB |
Output is correct |
38 |
Correct |
46 ms |
3276 KB |
Output is correct |
39 |
Correct |
9 ms |
3404 KB |
Output is correct |
40 |
Correct |
9 ms |
3404 KB |
Output is correct |
41 |
Correct |
75 ms |
3528 KB |
Output is correct |
42 |
Correct |
14 ms |
3660 KB |
Output is correct |
43 |
Correct |
10 ms |
3660 KB |
Output is correct |
44 |
Correct |
74 ms |
3660 KB |
Output is correct |
45 |
Correct |
12 ms |
3916 KB |
Output is correct |
46 |
Correct |
12 ms |
3916 KB |
Output is correct |
47 |
Correct |
96 ms |
4012 KB |
Output is correct |
48 |
Correct |
14 ms |
4228 KB |
Output is correct |
49 |
Correct |
14 ms |
4172 KB |
Output is correct |
50 |
Correct |
112 ms |
4260 KB |
Output is correct |
51 |
Correct |
16 ms |
4428 KB |
Output is correct |
52 |
Correct |
16 ms |
4508 KB |
Output is correct |
53 |
Correct |
124 ms |
4432 KB |
Output is correct |
54 |
Correct |
18 ms |
4752 KB |
Output is correct |
55 |
Correct |
18 ms |
4692 KB |
Output is correct |
56 |
Correct |
151 ms |
4816 KB |
Output is correct |
57 |
Correct |
23 ms |
4940 KB |
Output is correct |
58 |
Correct |
20 ms |
4884 KB |
Output is correct |
59 |
Correct |
161 ms |
4924 KB |
Output is correct |
60 |
Correct |
22 ms |
5120 KB |
Output is correct |
61 |
Correct |
22 ms |
5188 KB |
Output is correct |
62 |
Correct |
205 ms |
5208 KB |
Output is correct |
63 |
Correct |
167 ms |
5248 KB |
Output is correct |
64 |
Correct |
212 ms |
5124 KB |
Output is correct |
65 |
Correct |
210 ms |
5228 KB |
Output is correct |
66 |
Correct |
168 ms |
5316 KB |
Output is correct |
67 |
Correct |
130 ms |
5228 KB |
Output is correct |
68 |
Correct |
61 ms |
5188 KB |
Output is correct |
69 |
Correct |
59 ms |
5256 KB |
Output is correct |
70 |
Correct |
44 ms |
5172 KB |
Output is correct |
71 |
Correct |
54 ms |
5164 KB |
Output is correct |
72 |
Correct |
47 ms |
5164 KB |
Output is correct |
73 |
Correct |
54 ms |
5432 KB |
Output is correct |
74 |
Correct |
94 ms |
5436 KB |
Output is correct |
75 |
Correct |
106 ms |
5504 KB |
Output is correct |
76 |
Correct |
124 ms |
5424 KB |
Output is correct |
77 |
Correct |
106 ms |
5500 KB |
Output is correct |
78 |
Correct |
117 ms |
5444 KB |
Output is correct |
79 |
Correct |
86 ms |
5484 KB |
Output is correct |
80 |
Correct |
101 ms |
5404 KB |
Output is correct |
81 |
Correct |
116 ms |
5472 KB |
Output is correct |
82 |
Correct |
113 ms |
5364 KB |
Output is correct |
83 |
Correct |
132 ms |
5440 KB |
Output is correct |
84 |
Correct |
119 ms |
5436 KB |
Output is correct |
85 |
Correct |
115 ms |
5388 KB |
Output is correct |
86 |
Correct |
126 ms |
5440 KB |
Output is correct |
87 |
Correct |
138 ms |
5364 KB |
Output is correct |
88 |
Correct |
136 ms |
5380 KB |
Output is correct |
89 |
Correct |
139 ms |
5324 KB |
Output is correct |
90 |
Correct |
139 ms |
5316 KB |
Output is correct |
91 |
Correct |
138 ms |
5384 KB |
Output is correct |
92 |
Correct |
147 ms |
5352 KB |
Output is correct |