# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105466 | Zone_zonee | Mecho (IOI09_mecho) | C++17 | 121 ms | 7084 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;
int n, s;
char inp[808][808];
int bee[808][808];
int dis[808][808];
const int dr[] = {1, -1, 0, 0}, dc[] = {0, 0, 1, -1};
pair<int, int> st;
bool solve(int mid){
queue<tuple<int, int, int>> q;
q.emplace(st.first, st.second, 0);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) dis[i][j] = (inp[i][j] == 'M' ? 0 : 1e9);
while(!q.empty()){
auto [x, y, d1] = q.front(); q.pop();
if(dis[x][y] < d1 || (dis[x][y] / s >= bee[x][y] - mid && bee[x][y] != -1)) continue;
if(inp[x][y] == 'D') return true;
for(int i = 0; i < 4; ++i){
int nx = x+dr[i];
int ny = y+dc[i];
if(nx <= 0 || nx > n || ny <= 0 || ny > n) continue;
if(inp[nx][ny] != 'T' && dis[nx][ny] > d1 + 1){
q.emplace(nx, ny, dis[nx][ny] = d1+1);
}
}
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
queue<pair<int, int>> q;
cin >> n >> s;
memset(bee, -1, sizeof bee);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j){
cin >> inp[i][j];
if(inp[i][j] == 'M') st = {i, j};
else if(inp[i][j] == 'H'){
q.emplace(i, j);
bee[i][j] = 0;
}
}
while(!q.empty()){
auto [x, y] = q.front(); q.pop();
for(int i = 0; i < 4; ++i){
int nx = x+dr[i];
int ny = y+dc[i];
if(nx <= 0 || nx > n || ny <= 0 || ny > n) continue;
if(inp[nx][ny] != 'G' || bee[nx][ny] != -1) continue;
bee[nx][ny] = bee[x][y] + 1;
q.emplace(nx, ny);
}
}
int l = 0, r = 1e6, ans = -1;
while(l <= r){
int mid = (l+r)>>1;
if(solve(mid)) ans = mid, l = mid+1;
else r = mid-1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |