답안 #973040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973040 2024-05-01T12:48:16 Z njoop Mecho (IOI09_mecho) C++14
84 / 100
245 ms 11028 KB
#include <bits/stdc++.h>
#define pi pair<int, int>
#define ti tuple<int, int, int>
#define tii tuple<int, int, int, int>
using namespace std;

int n, s, bee[810][810], stx, sty, enx, eny, cx, cy, cs, cdi, l=0, r=1e9, mid;
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
pi mec[810][810];
vector<pi> hi;
char arr[810][810];

bool solve(int mn) {
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            mec[i][j] = {1e9, 1e9};
        }
    }
    queue<tii> q;
    q.push({stx, sty, 0, 0});
    while(q.size()) {
        cx = get<0>(q.front());
        cy = get<1>(q.front());
        cdi = get<2>(q.front());
        cs = get<3>(q.front());
        q.pop();
        if(cs == s) {
            cs = 0;
            cdi++;
        }
        if(cx < 1 || cx > n || cy < 1 || cy > n || arr[cx][cy] == 'T' || mec[cx][cy].first <= cdi) continue;
        if(mec[cx][cy].first == cdi && mec[cx][cy].second <= cs) continue;
        if(cdi+mn >= bee[cx][cy]) continue;
        mec[cx][cy] = {cdi, cs};
        for(int i=0; i<4; i++) {
            q.push({cx+di[i], cy+dj[i], cdi, cs+1});
        }
    }
    return mec[enx][eny].first != 1e9;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> s;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            bee[i][j] = 1e9;
            cin >> arr[i][j];
            if(arr[i][j] == 'M') {
                stx = i;
                sty = j;
            } else if(arr[i][j] == 'D') {
                enx = i;
                eny = j;
            } else if(arr[i][j] == 'H') {
                hi.push_back({i, j});
            }
        }
    }
    queue<ti> q;
    for(auto i: hi) {
        q.push({i.first, i.second, 0});
    }
    while(q.size()) {
        cx = get<0>(q.front());
        cy = get<1>(q.front());
        cdi = get<2>(q.front());
        q.pop();
        if(cx < 1 || cx > n || cy < 1 || cy > n || arr[cx][cy] == 'T' || bee[cx][cy] <= cdi) continue;
        bee[cx][cy] = cdi;
        for(int i=0; i<4; i++) {
            q.push({cx+di[i], cy+dj[i], cdi+1});
        }
    }
    while(l < r) {
        mid = (l+r)>>1;
        if(solve(mid)) {
            l = mid+1;
        } else {
            r = mid;
        }
    }
    cout << l-1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Correct 1 ms 4440 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Incorrect 135 ms 9472 KB Output isn't correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Incorrect 1 ms 4444 KB Output isn't correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 2 ms 4596 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 8 ms 7260 KB Output is correct
34 Correct 9 ms 7260 KB Output is correct
35 Correct 36 ms 7476 KB Output is correct
36 Correct 9 ms 7516 KB Output is correct
37 Correct 10 ms 7508 KB Output is correct
38 Correct 44 ms 7516 KB Output is correct
39 Correct 12 ms 7772 KB Output is correct
40 Correct 14 ms 7772 KB Output is correct
41 Correct 58 ms 7768 KB Output is correct
42 Correct 13 ms 7768 KB Output is correct
43 Correct 14 ms 7860 KB Output is correct
44 Correct 97 ms 8040 KB Output is correct
45 Correct 17 ms 8168 KB Output is correct
46 Correct 22 ms 8088 KB Output is correct
47 Correct 98 ms 8536 KB Output is correct
48 Correct 20 ms 8284 KB Output is correct
49 Correct 22 ms 8360 KB Output is correct
50 Correct 112 ms 8360 KB Output is correct
51 Correct 24 ms 8536 KB Output is correct
52 Correct 26 ms 8568 KB Output is correct
53 Correct 144 ms 8900 KB Output is correct
54 Correct 28 ms 8540 KB Output is correct
55 Correct 36 ms 8796 KB Output is correct
56 Correct 159 ms 8784 KB Output is correct
57 Correct 28 ms 8932 KB Output is correct
58 Correct 29 ms 8984 KB Output is correct
59 Correct 185 ms 9024 KB Output is correct
60 Correct 32 ms 9040 KB Output is correct
61 Correct 34 ms 9044 KB Output is correct
62 Correct 199 ms 9300 KB Output is correct
63 Correct 168 ms 9184 KB Output is correct
64 Correct 230 ms 9300 KB Output is correct
65 Correct 245 ms 9236 KB Output is correct
66 Correct 168 ms 9172 KB Output is correct
67 Correct 164 ms 9052 KB Output is correct
68 Correct 77 ms 9388 KB Output is correct
69 Correct 72 ms 9332 KB Output is correct
70 Correct 65 ms 9808 KB Output is correct
71 Correct 54 ms 9224 KB Output is correct
72 Correct 55 ms 9304 KB Output is correct
73 Correct 60 ms 10784 KB Output is correct
74 Correct 108 ms 10604 KB Output is correct
75 Correct 116 ms 11028 KB Output is correct
76 Correct 103 ms 10828 KB Output is correct
77 Correct 107 ms 10836 KB Output is correct
78 Correct 125 ms 10576 KB Output is correct
79 Correct 97 ms 10836 KB Output is correct
80 Correct 106 ms 10580 KB Output is correct
81 Correct 116 ms 10512 KB Output is correct
82 Correct 116 ms 10576 KB Output is correct
83 Correct 141 ms 10404 KB Output is correct
84 Correct 117 ms 10264 KB Output is correct
85 Correct 137 ms 10180 KB Output is correct
86 Correct 130 ms 10444 KB Output is correct
87 Correct 146 ms 10700 KB Output is correct
88 Correct 156 ms 9888 KB Output is correct
89 Correct 161 ms 10108 KB Output is correct
90 Correct 147 ms 10168 KB Output is correct
91 Correct 143 ms 10192 KB Output is correct
92 Correct 136 ms 10104 KB Output is correct