답안 #535609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535609 2022-03-10T16:35:55 Z louiskwok Mecho (IOI09_mecho) C++17
84 / 100
198 ms 9300 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') 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 (success) cout << lo << endl;
    else if (lo==hi&&possible(lo)) cout << lo << endl;
    else cout << -1 << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 852 KB Output is correct
2 Incorrect 1 ms 980 KB Output isn't correct
3 Correct 1 ms 852 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 136 ms 7192 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 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 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 2 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 2 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 1 ms 1236 KB Output is correct
32 Correct 1 ms 1364 KB Output is correct
33 Correct 11 ms 2672 KB Output is correct
34 Correct 11 ms 3284 KB Output is correct
35 Correct 28 ms 4428 KB Output is correct
36 Correct 13 ms 3028 KB Output is correct
37 Correct 14 ms 3668 KB Output is correct
38 Correct 31 ms 4964 KB Output is correct
39 Correct 18 ms 3284 KB Output is correct
40 Correct 24 ms 4092 KB Output is correct
41 Correct 67 ms 5496 KB Output is correct
42 Correct 22 ms 3572 KB Output is correct
43 Correct 21 ms 4380 KB Output is correct
44 Correct 49 ms 6040 KB Output is correct
45 Correct 24 ms 3732 KB Output is correct
46 Correct 26 ms 4736 KB Output is correct
47 Correct 87 ms 6548 KB Output is correct
48 Correct 34 ms 4096 KB Output is correct
49 Correct 30 ms 5080 KB Output is correct
50 Correct 74 ms 7036 KB Output is correct
51 Correct 33 ms 4328 KB Output is correct
52 Correct 38 ms 5344 KB Output is correct
53 Correct 119 ms 7540 KB Output is correct
54 Correct 42 ms 4500 KB Output is correct
55 Correct 42 ms 5680 KB Output is correct
56 Correct 117 ms 7964 KB Output is correct
57 Correct 44 ms 4848 KB Output is correct
58 Correct 44 ms 6052 KB Output is correct
59 Correct 161 ms 8468 KB Output is correct
60 Correct 53 ms 5032 KB Output is correct
61 Correct 53 ms 6252 KB Output is correct
62 Correct 164 ms 9048 KB Output is correct
63 Correct 158 ms 9036 KB Output is correct
64 Correct 187 ms 9104 KB Output is correct
65 Correct 181 ms 9020 KB Output is correct
66 Correct 198 ms 8940 KB Output is correct
67 Correct 138 ms 8908 KB Output is correct
68 Correct 78 ms 8580 KB Output is correct
69 Correct 65 ms 8652 KB Output is correct
70 Correct 67 ms 8512 KB Output is correct
71 Correct 81 ms 8384 KB Output is correct
72 Correct 59 ms 6588 KB Output is correct
73 Correct 57 ms 9300 KB Output is correct
74 Correct 81 ms 9252 KB Output is correct
75 Correct 83 ms 9108 KB Output is correct
76 Correct 113 ms 8996 KB Output is correct
77 Correct 93 ms 9268 KB Output is correct
78 Correct 95 ms 6720 KB Output is correct
79 Correct 79 ms 6288 KB Output is correct
80 Correct 84 ms 6396 KB Output is correct
81 Correct 109 ms 6476 KB Output is correct
82 Correct 79 ms 6128 KB Output is correct
83 Correct 97 ms 6712 KB Output is correct
84 Correct 88 ms 6672 KB Output is correct
85 Correct 92 ms 6620 KB Output is correct
86 Correct 119 ms 6852 KB Output is correct
87 Correct 92 ms 6576 KB Output is correct
88 Correct 102 ms 7060 KB Output is correct
89 Correct 98 ms 6660 KB Output is correct
90 Correct 149 ms 7036 KB Output is correct
91 Correct 133 ms 6768 KB Output is correct
92 Correct 103 ms 6948 KB Output is correct