답안 #535721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535721 2022-03-11T03:04:06 Z louiskwok Mecho (IOI09_mecho) C++17
61 / 100
174 ms 13128 KB
#include <bits/stdc++.h>
using namespace std;
bool visited[805][805];
int distBee[805][805];
int distBear[805][805];
char g[805][805];
int dr[] = {-1,0,1,0};
int dc[] = {0,1,0,-1};
int n,s,sr,sc,er,ec,mxtime;
bool success;
bool possible(int t) {
    memset(visited,0,sizeof visited);
    queue < pair <pair<int,int>,int> > bfs;
    bfs.push({{sr,sc},0});
    visited[sr][sc] = true;
    distBear[sr][sc] = t;
    while (!bfs.empty()) {
        int curR = bfs.front().first.first;
        int curC = bfs.front().first.second;
        int steps = 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]+((steps+1)%s==0?1:0)>=distBee[nr][nc]) continue;
            visited[nr][nc] = true;
            distBear[nr][nc] = distBear[curR][curC] + ((steps+1)%s==0?1:0);
            bfs.push({{nr,nc},steps+1});
        }
    }
    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];
            distBee[i][j]=1000000;
            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;
                distBee[i][j] = 0;
                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]!='G') 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(mid)) lo = mid;
        else hi = mid-1;
    }
    if (!success) cout << -1/0 << endl;
    else cout << lo << endl;
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:73:29: warning: division by zero [-Wdiv-by-zero]
   73 |     if (!success) cout << -1/0 << endl;
      |                           ~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 852 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Runtime error 2 ms 1748 KB Execution killed with signal 8
6 Correct 1 ms 980 KB Output is correct
7 Correct 103 ms 5712 KB Output is correct
8 Runtime error 2 ms 1748 KB Execution killed with signal 8
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 Correct 1 ms 1364 KB Output is correct
13 Incorrect 1 ms 1108 KB Output isn't correct
14 Runtime error 2 ms 2388 KB Execution killed with signal 8
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 980 KB Output is correct
19 Correct 1 ms 980 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 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 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 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 1 ms 1236 KB Output is correct
32 Correct 1 ms 1364 KB Output is correct
33 Correct 10 ms 2512 KB Output is correct
34 Correct 11 ms 2772 KB Output is correct
35 Correct 28 ms 3412 KB Output is correct
36 Correct 13 ms 2728 KB Output is correct
37 Correct 13 ms 3092 KB Output is correct
38 Correct 31 ms 3784 KB Output is correct
39 Correct 17 ms 3080 KB Output is correct
40 Correct 17 ms 3388 KB Output is correct
41 Correct 43 ms 4016 KB Output is correct
42 Correct 20 ms 3208 KB Output is correct
43 Correct 21 ms 3596 KB Output is correct
44 Correct 56 ms 4488 KB Output is correct
45 Correct 23 ms 3532 KB Output is correct
46 Correct 24 ms 3916 KB Output is correct
47 Correct 64 ms 4760 KB Output is correct
48 Correct 27 ms 3660 KB Output is correct
49 Correct 30 ms 4236 KB Output is correct
50 Correct 77 ms 5192 KB Output is correct
51 Correct 32 ms 3972 KB Output is correct
52 Correct 33 ms 4512 KB Output is correct
53 Correct 95 ms 5548 KB Output is correct
54 Correct 38 ms 4160 KB Output is correct
55 Correct 38 ms 4772 KB Output is correct
56 Correct 107 ms 5904 KB Output is correct
57 Correct 41 ms 4428 KB Output is correct
58 Correct 43 ms 5064 KB Output is correct
59 Correct 124 ms 6128 KB Output is correct
60 Correct 49 ms 4640 KB Output is correct
61 Correct 48 ms 5248 KB Output is correct
62 Correct 138 ms 6600 KB Output is correct
63 Runtime error 119 ms 13128 KB Execution killed with signal 8
64 Correct 174 ms 6580 KB Output is correct
65 Correct 172 ms 6568 KB Output is correct
66 Correct 136 ms 6520 KB Output is correct
67 Runtime error 133 ms 13128 KB Execution killed with signal 8
68 Runtime error 77 ms 12684 KB Execution killed with signal 8
69 Correct 75 ms 6568 KB Output is correct
70 Correct 60 ms 6588 KB Output is correct
71 Correct 62 ms 6604 KB Output is correct
72 Incorrect 55 ms 4620 KB Output isn't correct
73 Incorrect 86 ms 6768 KB Output isn't correct
74 Correct 77 ms 6824 KB Output is correct
75 Correct 88 ms 6920 KB Output is correct
76 Correct 79 ms 6812 KB Output is correct
77 Correct 83 ms 6788 KB Output is correct
78 Runtime error 93 ms 10956 KB Execution killed with signal 8
79 Correct 71 ms 5324 KB Output is correct
80 Correct 76 ms 5328 KB Output is correct
81 Correct 90 ms 5420 KB Output is correct
82 Correct 81 ms 5208 KB Output is correct
83 Runtime error 97 ms 11048 KB Execution killed with signal 8
84 Correct 97 ms 5564 KB Output is correct
85 Correct 97 ms 5408 KB Output is correct
86 Correct 94 ms 5528 KB Output is correct
87 Correct 91 ms 5324 KB Output is correct
88 Runtime error 101 ms 11272 KB Execution killed with signal 8
89 Correct 94 ms 5572 KB Output is correct
90 Correct 101 ms 5560 KB Output is correct
91 Correct 107 ms 5508 KB Output is correct
92 Correct 99 ms 5580 KB Output is correct