답안 #886619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886619 2023-12-12T12:32:41 Z gnu Mecho (IOI09_mecho) C++14
27 / 100
174 ms 11604 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()
{
    n, S; 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, 1e9   ));
    for (auto x : honey) {
        mq.push(x);
        vis[x.i][x.j] = 1;
        dist[x.i][x.j] = 0;
    }
    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 = -1, 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();
}

Compilation message

mecho.cpp: In function 'void solve()':
mecho.cpp:17:5: warning: left operand of comma operator has no effect [-Wunused-value]
   17 |     n, S; cin >> n >> S;
      |     ^
mecho.cpp:17:9: warning: right operand of comma operator has no effect [-Wunused-value]
   17 |     n, S; cin >> n >> S;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 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 98 ms 11396 KB Output isn't correct
8 Correct 0 ms 348 KB Output is 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 Correct 1 ms 580 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 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 6 ms 2544 KB Output is correct
34 Correct 7 ms 2588 KB Output is correct
35 Incorrect 21 ms 2556 KB Output isn't correct
36 Correct 7 ms 3164 KB Output is correct
37 Correct 7 ms 3160 KB Output is correct
38 Incorrect 26 ms 3256 KB Output isn't correct
39 Correct 9 ms 3900 KB Output is correct
40 Correct 10 ms 3944 KB Output is correct
41 Incorrect 36 ms 3940 KB Output isn't correct
42 Correct 10 ms 4724 KB Output is correct
43 Correct 10 ms 4724 KB Output is correct
44 Incorrect 45 ms 4700 KB Output isn't correct
45 Correct 13 ms 5588 KB Output is correct
46 Correct 13 ms 5576 KB Output is correct
47 Incorrect 64 ms 5596 KB Output isn't correct
48 Correct 16 ms 6588 KB Output is correct
49 Correct 17 ms 6608 KB Output is correct
50 Incorrect 65 ms 6608 KB Output isn't correct
51 Correct 18 ms 7640 KB Output is correct
52 Correct 20 ms 7668 KB Output is correct
53 Incorrect 81 ms 7600 KB Output isn't correct
54 Correct 25 ms 8812 KB Output is correct
55 Correct 25 ms 8772 KB Output is correct
56 Incorrect 91 ms 8812 KB Output isn't correct
57 Correct 22 ms 10012 KB Output is correct
58 Correct 22 ms 9980 KB Output is correct
59 Incorrect 111 ms 9996 KB Output isn't correct
60 Correct 26 ms 11376 KB Output is correct
61 Correct 27 ms 11324 KB Output is correct
62 Incorrect 129 ms 11332 KB Output isn't correct
63 Incorrect 94 ms 11320 KB Output isn't correct
64 Incorrect 172 ms 11344 KB Output isn't correct
65 Correct 174 ms 11516 KB Output is correct
66 Correct 117 ms 11312 KB Output is correct
67 Correct 119 ms 11320 KB Output is correct
68 Correct 62 ms 11340 KB Output is correct
69 Incorrect 70 ms 11604 KB Output isn't correct
70 Correct 48 ms 11372 KB Output is correct
71 Correct 55 ms 11444 KB Output is correct
72 Correct 47 ms 11420 KB Output is correct
73 Correct 53 ms 11404 KB Output is correct
74 Incorrect 71 ms 11416 KB Output isn't correct
75 Incorrect 78 ms 11404 KB Output isn't correct
76 Incorrect 73 ms 11400 KB Output isn't correct
77 Incorrect 74 ms 11408 KB Output isn't correct
78 Correct 78 ms 11408 KB Output is correct
79 Incorrect 71 ms 11404 KB Output isn't correct
80 Incorrect 76 ms 11316 KB Output isn't correct
81 Incorrect 81 ms 11288 KB Output isn't correct
82 Incorrect 66 ms 11364 KB Output isn't correct
83 Incorrect 86 ms 11420 KB Output isn't correct
84 Incorrect 88 ms 11388 KB Output isn't correct
85 Incorrect 90 ms 11552 KB Output isn't correct
86 Incorrect 84 ms 11348 KB Output isn't correct
87 Incorrect 89 ms 11376 KB Output isn't correct
88 Incorrect 93 ms 11408 KB Output isn't correct
89 Incorrect 88 ms 11324 KB Output isn't correct
90 Incorrect 99 ms 11360 KB Output isn't correct
91 Incorrect 89 ms 11340 KB Output isn't correct
92 Incorrect 89 ms 11444 KB Output isn't correct