Submission #972934

#TimeUsernameProblemLanguageResultExecution timeMemory
972934jadai007Mecho (IOI09_mecho)C++17
18 / 100
261 ms65536 KiB
#include<bits/stdc++.h> using namespace std; int n,s, bee[808][808], xx[] = {0, 0, -1, 1}, xy[] = {-1, 1, 0, 0}, bear[808][808], ans; char mp[808][808]; pair<int, int> start, en; queue<tuple<int, int, int>> q; bool solve(int mid){ for(int i = 1; i<=n; ++i) for(int j = 1; j<=n; ++j) bear[i][j] = 1e9; bear[start.first][start.second] = mid*s; q.emplace(start.first, start.second, mid*s); while(!q.empty()){ int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop(); if(x == en.first && y == en.second) return true; if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue; else if((w+s-1)/s > bee[x][y]) continue; bear[x][y] = w; for(int i = 0; i<4; ++i){ int nx = x + xx[i]; int ny = y + xy[i]; if(nx < 1 || ny < 1 || nx > n || ny > n || mp[nx][ny] == 'T' || mp[nx][ny] == 'H') continue; if(bear[nx][ny] > w + 1) q.emplace(nx, ny, w + 1); } } return false; } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> s; for(int i = 1; i<=n; ++i){ for(int j = 1; j<=n; ++j){ cin >> mp[i][j]; if(mp[i][j] == 'M') start = {i, j}; else if(mp[i][j] == 'D') en = {i, j}; } } for(int i = 1; i<=n; ++i) for(int j = 1; j<=n; ++j) bee[i][j] = 1e9; for(int i = 1; i<=n; ++i){ for(int j = 1; j<=n; ++j){ if(mp[i][j] == 'H'){ bee[i][j] = 0; q.emplace(i, j, 0); } } } while(!q.empty()){ int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop(); for(int i = 0; i<4; ++i){ int nx = x + xx[i]; int ny = y + xy[i]; if(nx < 1 || n < 1 || nx > n || ny > n || mp[nx][ny] == 'T') continue; if(bee[nx][ny] > w + 1){ bee[nx][ny] = w + 1; q.emplace(nx, ny, w + 1); } } } int l = 1, r = 1e9; while(l <= r){ int mid = (l + r) >> 1; while(!q.empty()) q.pop(); if(solve(mid)){ ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans; }

Compilation message (stderr)

mecho.cpp: In function 'bool solve(int)':
mecho.cpp:17:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   17 |         if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...