Submission #535618

# Submission time Handle Problem Language Result Execution time Memory
535618 2022-03-10T16:47:50 Z louiskwok Mecho (IOI09_mecho) C++17
73 / 100
232 ms 9364 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<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 = mxtime;
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 1 ms 980 KB Output isn't correct
3 Correct 1 ms 980 KB Output is correct
4 Incorrect 1 ms 980 KB Output isn't correct
5 Correct 1 ms 980 KB Output is correct
6 Incorrect 1 ms 980 KB Output isn't correct
7 Incorrect 114 ms 9204 KB Output isn't correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Incorrect 1 ms 1364 KB Output isn't correct
13 Incorrect 1 ms 1236 KB Output isn't correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1364 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 2 ms 1364 KB Output is correct
30 Correct 2 ms 1508 KB Output is correct
31 Correct 2 ms 1364 KB Output is correct
32 Correct 2 ms 1460 KB Output is correct
33 Correct 12 ms 3156 KB Output is correct
34 Correct 14 ms 4360 KB Output is correct
35 Correct 30 ms 4436 KB Output is correct
36 Correct 15 ms 3540 KB Output is correct
37 Correct 20 ms 4820 KB Output is correct
38 Correct 43 ms 5020 KB Output is correct
39 Correct 22 ms 3792 KB Output is correct
40 Correct 22 ms 5300 KB Output is correct
41 Correct 53 ms 5460 KB Output is correct
42 Correct 22 ms 4180 KB Output is correct
43 Correct 25 ms 5988 KB Output is correct
44 Correct 77 ms 6028 KB Output is correct
45 Correct 28 ms 4420 KB Output is correct
46 Correct 32 ms 6480 KB Output is correct
47 Correct 95 ms 6544 KB Output is correct
48 Correct 34 ms 4784 KB Output is correct
49 Correct 41 ms 6928 KB Output is correct
50 Correct 109 ms 7056 KB Output is correct
51 Correct 43 ms 5160 KB Output is correct
52 Correct 45 ms 7388 KB Output is correct
53 Correct 146 ms 7572 KB Output is correct
54 Correct 42 ms 5416 KB Output is correct
55 Correct 44 ms 7768 KB Output is correct
56 Correct 150 ms 8092 KB Output is correct
57 Correct 53 ms 5740 KB Output is correct
58 Correct 63 ms 8244 KB Output is correct
59 Correct 179 ms 8580 KB Output is correct
60 Correct 60 ms 6076 KB Output is correct
61 Correct 76 ms 8540 KB Output is correct
62 Correct 207 ms 9100 KB Output is correct
63 Correct 142 ms 8944 KB Output is correct
64 Correct 232 ms 9076 KB Output is correct
65 Correct 208 ms 9196 KB Output is correct
66 Correct 175 ms 9040 KB Output is correct
67 Correct 177 ms 8896 KB Output is correct
68 Correct 99 ms 8684 KB Output is correct
69 Correct 78 ms 8876 KB Output is correct
70 Correct 74 ms 8500 KB Output is correct
71 Correct 79 ms 8456 KB Output is correct
72 Incorrect 117 ms 8896 KB Output isn't correct
73 Incorrect 120 ms 9292 KB Output isn't correct
74 Correct 94 ms 9364 KB Output is correct
75 Correct 96 ms 9336 KB Output is correct
76 Correct 110 ms 9216 KB Output is correct
77 Correct 127 ms 9296 KB Output is correct
78 Correct 111 ms 6760 KB Output is correct
79 Correct 87 ms 9264 KB Output is correct
80 Correct 114 ms 6752 KB Output is correct
81 Correct 136 ms 6604 KB Output is correct
82 Correct 99 ms 6860 KB Output is correct
83 Correct 112 ms 6732 KB Output is correct
84 Correct 132 ms 9292 KB Output is correct
85 Correct 145 ms 6860 KB Output is correct
86 Correct 125 ms 6724 KB Output is correct
87 Correct 118 ms 7100 KB Output is correct
88 Correct 119 ms 7056 KB Output is correct
89 Correct 152 ms 9244 KB Output is correct
90 Correct 154 ms 8268 KB Output is correct
91 Correct 133 ms 9244 KB Output is correct
92 Correct 133 ms 7200 KB Output is correct