# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535619 |
2022-03-10T16:49:52 Z |
louiskwok |
Mecho (IOI09_mecho) |
C++17 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
bool visited[805][805];
int distBee[805][805];
double distBear[805][805];
char g[805][805];
int dr[] = {-1,0,1,0};
int dc[] = {0,1,0,-1};
int n,sr,sc,er,ec,mxtime;
double s;
bool success;
bool possible(double t) {
memset(visited,0,sizeof visited);
queue < pair<int,int> > bfs;
distBear[sr][sc] = t;
bfs.push({sr,sc});
while (!bfs.empty()) {
int curR = bfs.front().first;
int curC = bfs.front().second;
bfs.pop();
for (int i=0;i<4;i++) {
int nr = curR + dr[i];
int nc = curC + dc[i];
if (nr<1||nr>n||nc<1||nc>n||visited[nr][nc]||g[nr][nc]=='T'||distBear[curR][curC]+(double)1/s>=(double)distBee[nr][nc]) continue;
visited[nr][nc] = true;
distBear[nr][nc] = distBear[curR][curC]+1/s;
bfs.push({nr,nc});
}
}
if (visited[er][ec]) {
success = true;
return true;
}
return false;
}
int main() {
queue < pair<int,int> > bfs;
cin >> n >> s;
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
cin >> g[i][j];
if (g[i][j]=='M') sr = i,sc = j;
else if (g[i][j]=='D') er = i,ec = j;
else if (g[i][j]=='H') {
visited[i][j] = true;
bfs.push({i,j});
}
}
}
while (!bfs.empty()) {
int curR = bfs.front().first;
int curC = bfs.front().second;
bfs.pop();
for (int i=0;i<4;i++) {
int nr = curR + dr[i];
int nc = curC + dc[i];
if (nr==sr&&nc==sc) distBee[nr][nc] = dist[curR][curC]+1;
if (nr<1||nr>n||nc<1||nc>n||visited[nr][nc]||g[nr][nc]=='T'||g[nr][nc]=='M') continue;
visited[nr][nc] = true;
distBee[nr][nc] = distBee[curR][curC]+1;
mxtime = max(mxtime,distBee[nr][nc]);
bfs.push({nr,nc});
}
}
int lo = 0,hi = distBee[sr][sc]-1;
while (lo<hi) {
int mid = (lo+hi+1)/2;
if (possible((double)mid)) lo = mid;
else hi = mid-1;
}
if (!possible(0)) cout << -1 << endl;
else cout << lo << endl;
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:57:51: error: 'dist' was not declared in this scope
57 | if (nr==sr&&nc==sc) distBee[nr][nc] = dist[curR][curC]+1;
| ^~~~