# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501150 | sidon | Mecho (IOI09_mecho) | C++17 | 211 ms | 6684 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define c(X, Y) (X * N + Y)
const int INF = 1e8;
const int di[4] = {-1, 1, 0, 0};
const int dj[4] = {0, 0, -1, 1};
int N, S, h[1<<20], m[1<<20], ans = -1, home;
string g[1<<10];
void BFS(char src, int *d, function<bool(int, int, int)> valid) {
fill(d, d + N * N, INF);
queue<int> q;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(g[i][j] == src)
d[c(i, j)] = 0, q.push(c(i, j));
else if(g[i][j] == 'D')
home = c(i, j);
while(!empty(q)) {
int k = q.front(), i = k / N, j = k % N; q.pop();
for(int s = 0; s < 4; s++) {
int x = i + di[s], y = j + dj[s], z = c(x, y);
if(min(x, y) < 0 || max(x, y) >= N || d[z] != INF) continue;
if(valid(x, y, d[k] + 1))
d[z] = d[k] + 1, q.push(z);
}
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> S;
for(int i = 0; i < N; i++)
cin >> g[i];
BFS('H', h, [&](int i, int j, int k) {
return g[i][j] & 1;
});
for(int b = 30; --b >= 0; ) {
ans += 1 << b;
BFS('M', m, [&](int i, int j, int k) {
return (g[i][j] & 1 || g[i][j] == 'D') && (k + S - 1) / S + ans <= h[c(i, j)];
});
if(m[home] == INF)
ans -= 1 << b;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |