답안 #886623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886623 2023-12-12T12:36:02 Z gnu Mecho (IOI09_mecho) C++14
23 / 100
178 ms 11576 KB
#include <bits/stdc++.h>
using namespace std;
int n, S;
vector<string> board;
vector<vector<int>> vis;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
struct point{
    int i, j;
    point(int i, int j) {
        this->i = i;
        this->j = j;
    }
};
void solve()
{
    cin >> n >> S;
    board = vector<string>(n);
    vis = vector<vector<int>> (n, vector<int> (n));
    for (int i = 0; i < n; ++i) cin >> board[i];
    point mecho(0,0), home(0,0);
    vector<point> honey;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (board[i][j] == 'H') honey.emplace_back(i, j);
            else if (board[i][j] == 'M') mecho = {i, j};
            else if (board[i][j] == 'D') home = {i, j};
        }
    }
    queue<point> mq;
    vector<vector<int>> dist(n, vector<int> (n, 0   ));
    for (auto x : honey) {
        mq.push(x);
        vis[x.i][x.j] = 1;
    }
    while (!mq.empty()) {
        point u = mq.front();
        mq.pop();
        for (int i = 0; i < 4; ++i) {
            if (u.i + dx[i] < 0 || u.i + dx[i] >= n || u.j + dy[i] < 0 || u.j + dy[i] >= n || vis[u.i+dx[i]][u.j+dy[i]] || (board[u.i+dx[i]][u.j+dy[i]] != 'G' && board[u.i+dx[i]][u.j+dy[i]] != 'M')) continue;
            mq.emplace(u.i + dx[i], u.j + dy[i]);
            vis[u.i + dx[i]][u.j + dy[i]] = 1;
            dist[u.i + dx[i]][u.j + dy[i]] = dist[u.i][u.j] + 1;
        }
    }
//    for (auto &x : dist)
//    {
//        for (auto y : x) cout << y << ' ';
//        cout << '\n';
//    }

    int l = 0, r = 1e9;
//    return;
    while (l + 1 < r) {
        vector<vector<int>> md(n, vector<int> (n));
        int m = (l + r) / 2;
        vis = vector<vector<int>> (n, vector<int> (n));
        queue<point> q;
        q.emplace(mecho.i, mecho.j);
        vis[mecho.i][mecho.j] = 1;
        if (m >= dist[mecho.i][mecho.j]) q.pop();
        while (!q.empty()) {
            point u = q.front();

            q.pop();
            for (int i = 0; i < 4; ++i) {
                int ni = u.i + dx[i], nj = u.j + dy[i];
                if (u.i + dx[i] < 0 || u.i + dx[i] >= n || u.j + dy[i] < 0 || u.j + dy[i] >= n || vis[u.i+dx[i]][u.j+dy[i]] || (board[u.i+dx[i]][u.j+dy[i]] != 'G' && board[u.i+dx[i]][u.j+dy[i]] != 'M')) continue;
                if (((md[u.i][u.j]+1) / S >= (dist[u.i][u.j] - m))) continue;
                q.emplace(ni, nj);
                md[ni][nj] = md[u.i][u.j] + 1;
                vis[ni][nj] = 1;
            }
        }
        bool ok = false;
        for (int i = 0; i < 4; ++i) {
            point u = home;
            if (u.i + dx[i] < 0 || u.i + dx[i] >= n || u.j + dy[i] < 0 || u.j + dy[i] >= n || (board[u.i+dx[i]][u.j+dy[i]] != 'G' && board[u.i+dx[i]][u.j+dy[i]] != 'M')) continue;
            if (((md[u.i][u.j]+1) / S >= (dist[u.i + dx[i]][u.j + dy[i]] - m))) continue;
            if (vis[home.i + dx[i]][home.j+dy[i]]) ok = true;
        }
        if (ok) {
            l = m;
        } else r = m;

    }
    cout << l;

}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 91 ms 11388 KB Output isn't correct
8 Incorrect 1 ms 600 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 9 ms 2548 KB Output is correct
34 Correct 7 ms 2552 KB Output is correct
35 Incorrect 20 ms 2808 KB Output isn't correct
36 Correct 7 ms 3164 KB Output is correct
37 Correct 8 ms 3196 KB Output is correct
38 Incorrect 27 ms 3164 KB Output isn't correct
39 Correct 14 ms 4184 KB Output is correct
40 Correct 10 ms 3884 KB Output is correct
41 Incorrect 39 ms 3900 KB Output isn't correct
42 Correct 11 ms 4912 KB Output is correct
43 Correct 10 ms 4720 KB Output is correct
44 Incorrect 46 ms 4700 KB Output isn't correct
45 Correct 13 ms 5612 KB Output is correct
46 Correct 14 ms 5612 KB Output is correct
47 Incorrect 55 ms 5636 KB Output isn't correct
48 Correct 16 ms 6608 KB Output is correct
49 Correct 17 ms 6576 KB Output is correct
50 Incorrect 76 ms 6824 KB Output isn't correct
51 Correct 18 ms 7668 KB Output is correct
52 Correct 20 ms 7660 KB Output is correct
53 Incorrect 84 ms 7608 KB Output isn't correct
54 Correct 24 ms 8780 KB Output is correct
55 Correct 25 ms 8780 KB Output is correct
56 Incorrect 88 ms 8808 KB Output isn't correct
57 Correct 23 ms 10012 KB Output is correct
58 Correct 23 ms 10016 KB Output is correct
59 Incorrect 113 ms 9992 KB Output isn't correct
60 Correct 28 ms 11324 KB Output is correct
61 Correct 28 ms 11324 KB Output is correct
62 Incorrect 134 ms 11304 KB Output isn't correct
63 Correct 96 ms 11328 KB Output is correct
64 Incorrect 178 ms 11312 KB Output isn't correct
65 Correct 165 ms 11324 KB Output is correct
66 Correct 117 ms 11328 KB Output is correct
67 Incorrect 127 ms 11576 KB Output isn't correct
68 Correct 62 ms 11364 KB Output is correct
69 Incorrect 68 ms 11372 KB Output isn't correct
70 Correct 58 ms 11400 KB Output is correct
71 Correct 48 ms 11420 KB Output is correct
72 Correct 49 ms 11320 KB Output is correct
73 Correct 46 ms 11404 KB Output is correct
74 Incorrect 69 ms 11348 KB Output isn't correct
75 Incorrect 86 ms 11372 KB Output isn't correct
76 Incorrect 71 ms 11408 KB Output isn't correct
77 Incorrect 95 ms 11440 KB Output isn't correct
78 Incorrect 82 ms 11404 KB Output isn't correct
79 Incorrect 69 ms 11420 KB Output isn't correct
80 Incorrect 70 ms 11436 KB Output isn't correct
81 Incorrect 80 ms 11304 KB Output isn't correct
82 Incorrect 74 ms 11344 KB Output isn't correct
83 Incorrect 100 ms 11360 KB Output isn't correct
84 Incorrect 81 ms 11352 KB Output isn't correct
85 Incorrect 92 ms 11368 KB Output isn't correct
86 Incorrect 86 ms 11424 KB Output isn't correct
87 Incorrect 89 ms 11356 KB Output isn't correct
88 Incorrect 88 ms 11352 KB Output isn't correct
89 Incorrect 90 ms 11484 KB Output isn't correct
90 Incorrect 104 ms 11372 KB Output isn't correct
91 Incorrect 112 ms 11392 KB Output isn't correct
92 Incorrect 104 ms 11364 KB Output isn't correct