# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
254311 |
2020-07-29T20:20:19 Z |
sandoval |
Mecho (IOI09_mecho) |
C++11 |
|
209 ms |
9468 KB |
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;
using ll = long long;
const int dx[] {0, -1, 0, 1};
const int dy[] {-1, 0, 1, 0};
constexpr int MAXS = 5+800;
constexpr int INF = 1e8;
char c[MAXS][MAXS];
int N,S, tb[MAXS][MAXS];
bool ok(int x, int y) {
return x >= 0 && y >= 0 && x < N && y < N;
}
void bfs_bees() {
queue<ii> q;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (c[i][j] == 'H') {
q.push({i,j});
tb[i][j] = 0;
} else {
tb[i][j] = INF;
}
}
}
while (!q.empty()) {
auto u = q.front(); q.pop();
for (int k = 0; k < 4; ++k) {
int newx = u.first+dx[k], newy = u.second+dy[k];
if (ok(newx, newy) && 1+tb[u.first][u.second] < tb[newx][newy] && c[newx][newy] == 'G') {
q.push({newx, newy});
tb[newx][newy] = 1+tb[u.first][u.second];
}
}
}
}
ii dist[MAXS][MAXS];
bool can(const ii& source, const ii& target, int t) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
dist[i][j] = {10*INF, 0};
}
}
queue<array<int,2>> q; q.push({source.first, source.second});
dist[source.first][source.second] = {t, S};
while (!q.empty()) {
auto u = q.front(); q.pop();
if (u[0] == target.first && u[1] == target.second) return true;
for (int k = 0; k < 4; ++k) {
int newx = u[0]+dx[k], newy = u[1]+dy[k];
ii newcost = dist[u[0]][u[1]];
newcost.second--;
if (newcost.second < 0) {
assert(newcost.second == -1);
newcost.first++;
newcost.second = S;
}
if (ok(newx, newy) && (c[newx][newy] == 'G' || c[newx][newy] == 'D') && (newcost.first < tb[newx][newy]) &&
(newcost.first < dist[newx][newy].first || (newcost.first == dist[newx][newy].first && newcost.second > dist[newx][newy].second))) {
q.push({newx, newy});
dist[newx][newy] = newcost;
}
}
}
return false;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> N >> S;
ii start, target;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> c[i][j];
if (c[i][j] == 'M') {
start = {i,j};
} else if (c[i][j] == 'D') {
target = {i,j};
}
}
}
bfs_bees();
int low = 0, high = INF, best = -1;
while (low <= high) {
int mid = (low+high) >> 1;
if (can(start, target, mid)) {
low = 1+mid;
best = mid;
} else {
high = mid-1;
}
}
cout << best << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
129 ms |
9468 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
512 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
768 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
512 KB |
Output isn't correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Incorrect |
1 ms |
768 KB |
Output isn't correct |
24 |
Correct |
1 ms |
768 KB |
Output is correct |
25 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
26 |
Correct |
1 ms |
896 KB |
Output is correct |
27 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
28 |
Correct |
1 ms |
896 KB |
Output is correct |
29 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
30 |
Correct |
1 ms |
896 KB |
Output is correct |
31 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
32 |
Correct |
1 ms |
1024 KB |
Output is correct |
33 |
Incorrect |
8 ms |
4096 KB |
Output isn't correct |
34 |
Correct |
8 ms |
4096 KB |
Output is correct |
35 |
Correct |
25 ms |
4096 KB |
Output is correct |
36 |
Incorrect |
10 ms |
4608 KB |
Output isn't correct |
37 |
Correct |
15 ms |
4608 KB |
Output is correct |
38 |
Correct |
37 ms |
4608 KB |
Output is correct |
39 |
Incorrect |
18 ms |
5120 KB |
Output isn't correct |
40 |
Correct |
12 ms |
5120 KB |
Output is correct |
41 |
Correct |
43 ms |
5240 KB |
Output is correct |
42 |
Incorrect |
14 ms |
5760 KB |
Output isn't correct |
43 |
Correct |
14 ms |
5760 KB |
Output is correct |
44 |
Correct |
58 ms |
5880 KB |
Output is correct |
45 |
Incorrect |
17 ms |
6272 KB |
Output isn't correct |
46 |
Correct |
16 ms |
6272 KB |
Output is correct |
47 |
Correct |
68 ms |
6300 KB |
Output is correct |
48 |
Incorrect |
20 ms |
6912 KB |
Output isn't correct |
49 |
Correct |
20 ms |
6904 KB |
Output is correct |
50 |
Correct |
81 ms |
6808 KB |
Output is correct |
51 |
Incorrect |
22 ms |
7424 KB |
Output isn't correct |
52 |
Correct |
24 ms |
7424 KB |
Output is correct |
53 |
Correct |
95 ms |
7424 KB |
Output is correct |
54 |
Incorrect |
27 ms |
8064 KB |
Output isn't correct |
55 |
Correct |
26 ms |
8056 KB |
Output is correct |
56 |
Correct |
114 ms |
8184 KB |
Output is correct |
57 |
Incorrect |
29 ms |
8576 KB |
Output isn't correct |
58 |
Correct |
32 ms |
8568 KB |
Output is correct |
59 |
Correct |
133 ms |
8568 KB |
Output is correct |
60 |
Incorrect |
32 ms |
9208 KB |
Output isn't correct |
61 |
Correct |
36 ms |
9216 KB |
Output is correct |
62 |
Correct |
184 ms |
9208 KB |
Output is correct |
63 |
Incorrect |
181 ms |
9216 KB |
Output isn't correct |
64 |
Correct |
159 ms |
9216 KB |
Output is correct |
65 |
Incorrect |
209 ms |
9212 KB |
Output isn't correct |
66 |
Incorrect |
160 ms |
9208 KB |
Output isn't correct |
67 |
Incorrect |
185 ms |
9216 KB |
Output isn't correct |
68 |
Incorrect |
65 ms |
9336 KB |
Output isn't correct |
69 |
Correct |
59 ms |
9212 KB |
Output is correct |
70 |
Incorrect |
62 ms |
9208 KB |
Output isn't correct |
71 |
Incorrect |
61 ms |
9208 KB |
Output isn't correct |
72 |
Incorrect |
56 ms |
9208 KB |
Output isn't correct |
73 |
Incorrect |
99 ms |
9312 KB |
Output isn't correct |
74 |
Correct |
92 ms |
9312 KB |
Output is correct |
75 |
Incorrect |
101 ms |
9368 KB |
Output isn't correct |
76 |
Incorrect |
115 ms |
9316 KB |
Output isn't correct |
77 |
Incorrect |
117 ms |
9316 KB |
Output isn't correct |
78 |
Incorrect |
100 ms |
9340 KB |
Output isn't correct |
79 |
Correct |
79 ms |
9468 KB |
Output is correct |
80 |
Incorrect |
83 ms |
9348 KB |
Output isn't correct |
81 |
Incorrect |
85 ms |
9468 KB |
Output isn't correct |
82 |
Incorrect |
84 ms |
9348 KB |
Output isn't correct |
83 |
Incorrect |
137 ms |
9376 KB |
Output isn't correct |
84 |
Correct |
114 ms |
9352 KB |
Output is correct |
85 |
Incorrect |
115 ms |
9380 KB |
Output isn't correct |
86 |
Incorrect |
139 ms |
9248 KB |
Output isn't correct |
87 |
Correct |
134 ms |
9248 KB |
Output is correct |
88 |
Incorrect |
124 ms |
9300 KB |
Output isn't correct |
89 |
Correct |
117 ms |
9428 KB |
Output is correct |
90 |
Correct |
124 ms |
9308 KB |
Output is correct |
91 |
Correct |
167 ms |
9300 KB |
Output is correct |
92 |
Incorrect |
166 ms |
9428 KB |
Output isn't correct |