Submission #513886

# Submission time Handle Problem Language Result Execution time Memory
513886 2022-01-17T22:31:19 Z nhuang685 Mecho (IOI09_mecho) C++17
16 / 100
157 ms 4652 KB
#include <bits/stdc++.h>

#ifdef VSLOCAL
#include "debug/d.h"
#endif
#ifdef LOCAL
// Don't use this for USACO
#include "../../debug/d.h"
#endif

using namespace std;

using ll = long long;
using ld = long double;
#if defined(LOCAL) || defined(VSLOCAL)
#define dbg(...) line_info(__LINE__, #__VA_ARGS__), dbg1(__VA_ARGS__)
void nline() { cerr << '\n'; }
#else
#define dbg(...) 0
void nline() {}
#endif

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("log.txt", "w", stderr);
    #endif

    const array<int, 4> dx {-1, 0, 1, 0}, dy {0, 1, 0, -1};

    int N, S;
    cin >> N >> S;
    vector<vector<char>> grid (N, vector<char> (N));
    queue<pair<int, pair<int, int>>> q;
    vector<vector<int>> beetime (N, vector<int> (N, (int)1e9));
    vector<vector<bool>> visited (N, vector<bool> (N));
    pair<int, int> honey, home;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> grid[i][j];
            if (grid[i][j] == 'H') { 
                q.push({0, {i, j}}); 
                visited[i][j] = true;
                beetime[i][j] = 0;
            }
            else if (grid[i][j] == 'M') honey = {i, j};
            else if (grid[i][j] == 'D') home = {i, j};
        }
    }

    while (!q.empty()) {
        auto [dist, loc] = q.front();
        q.pop();

        for (int d = 0; d < 4; ++d) {
            pair<int, int> nloc = {loc.first + dx[d], loc.second + dy[d]};
            if (nloc.first < 0 || nloc.first >= N || nloc.second < 0 || nloc.second >= N || visited[nloc.first][nloc.second]) continue;
            if (grid[nloc.first][nloc.second] == 'G' || grid[nloc.first][nloc.second] == 'M') {
                visited[nloc.first][nloc.second] = true;
                beetime[nloc.first][nloc.second] = dist + S;
                q.push({dist + S, nloc});
            }
        }
    }
    dbg(beetime);

    auto good = [&](int val) {
        visited.assign(N, vector<bool> (N));
        visited[honey.first][honey.second] = true;
        q.push({val * S, honey});
        while (!q.empty()) {
            auto [dist, loc] = q.front();
            q.pop();

            for (int d = 0; d < 4; ++d) {
                pair<int, int> nloc = {loc.first + dx[d], loc.second + dy[d]};
                if (nloc.first < 0 || nloc.first >= N || nloc.second < 0 || nloc.second >= N 
                    || visited[nloc.first][nloc.second] || dist + 1 >= beetime[nloc.first][nloc.second]) continue;
                if (grid[nloc.first][nloc.second] == 'D') {
                    return true;
                }
                else if (grid[nloc.first][nloc.second] == 'G') {
                    visited[nloc.first][nloc.second] = true;
                    q.push({dist + 1, nloc});
                }
            }
        }
        return false;
    };

    int low = 0, high = 1e5;
    while (low < high) {
        int mid = (low + high + 1) / 2;
        if (good(mid)) low = mid;
        else high = mid - 1;
    }
    
    cout << low << '\n';
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:19:18: warning: statement has no effect [-Wunused-value]
   19 | #define dbg(...) 0
      |                  ^
mecho.cpp:68:5: note: in expansion of macro 'dbg'
   68 |     dbg(beetime);
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 77 ms 4368 KB Output is correct
8 Incorrect 1 ms 308 KB Output isn't correct
9 Incorrect 0 ms 204 KB Output isn't correct
10 Incorrect 0 ms 204 KB Output isn't correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 1 ms 312 KB Output isn't correct
16 Incorrect 1 ms 204 KB Output isn't correct
17 Incorrect 1 ms 204 KB Output isn't correct
18 Incorrect 1 ms 312 KB Output isn't correct
19 Incorrect 1 ms 204 KB Output isn't correct
20 Incorrect 0 ms 204 KB Output isn't correct
21 Incorrect 1 ms 204 KB Output isn't correct
22 Incorrect 1 ms 204 KB Output isn't correct
23 Incorrect 1 ms 332 KB Output isn't correct
24 Incorrect 1 ms 308 KB Output isn't correct
25 Incorrect 1 ms 300 KB Output isn't correct
26 Incorrect 1 ms 332 KB Output isn't correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Incorrect 1 ms 312 KB Output isn't correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Incorrect 0 ms 332 KB Output isn't correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Incorrect 1 ms 332 KB Output isn't correct
33 Incorrect 5 ms 972 KB Output isn't correct
34 Incorrect 6 ms 1092 KB Output isn't correct
35 Incorrect 23 ms 1088 KB Output isn't correct
36 Incorrect 5 ms 1312 KB Output isn't correct
37 Incorrect 5 ms 1332 KB Output isn't correct
38 Incorrect 21 ms 1332 KB Output isn't correct
39 Incorrect 6 ms 1480 KB Output isn't correct
40 Incorrect 6 ms 1480 KB Output isn't correct
41 Incorrect 28 ms 1588 KB Output isn't correct
42 Incorrect 9 ms 1868 KB Output isn't correct
43 Incorrect 9 ms 1868 KB Output isn't correct
44 Incorrect 34 ms 1872 KB Output isn't correct
45 Incorrect 13 ms 2116 KB Output isn't correct
46 Incorrect 10 ms 2112 KB Output isn't correct
47 Incorrect 43 ms 2192 KB Output isn't correct
48 Incorrect 11 ms 2436 KB Output isn't correct
49 Incorrect 11 ms 2432 KB Output isn't correct
50 Incorrect 48 ms 2556 KB Output isn't correct
51 Incorrect 13 ms 2928 KB Output isn't correct
52 Incorrect 13 ms 2888 KB Output isn't correct
53 Incorrect 60 ms 2940 KB Output isn't correct
54 Incorrect 17 ms 3276 KB Output isn't correct
55 Incorrect 19 ms 3276 KB Output isn't correct
56 Incorrect 76 ms 3348 KB Output isn't correct
57 Incorrect 18 ms 3652 KB Output isn't correct
58 Incorrect 17 ms 3780 KB Output isn't correct
59 Incorrect 76 ms 3800 KB Output isn't correct
60 Incorrect 19 ms 4152 KB Output isn't correct
61 Incorrect 19 ms 4172 KB Output isn't correct
62 Incorrect 102 ms 4244 KB Output isn't correct
63 Correct 84 ms 4256 KB Output is correct
64 Correct 157 ms 4172 KB Output is correct
65 Correct 132 ms 4248 KB Output is correct
66 Correct 130 ms 4236 KB Output is correct
67 Incorrect 115 ms 4236 KB Output isn't correct
68 Correct 54 ms 4244 KB Output is correct
69 Correct 42 ms 4284 KB Output is correct
70 Correct 45 ms 4256 KB Output is correct
71 Correct 39 ms 4300 KB Output is correct
72 Incorrect 35 ms 4300 KB Output isn't correct
73 Incorrect 35 ms 4652 KB Output isn't correct
74 Incorrect 32 ms 4632 KB Output isn't correct
75 Incorrect 35 ms 4628 KB Output isn't correct
76 Incorrect 42 ms 4640 KB Output isn't correct
77 Incorrect 37 ms 4556 KB Output isn't correct
78 Incorrect 67 ms 4556 KB Output isn't correct
79 Incorrect 35 ms 4616 KB Output isn't correct
80 Incorrect 39 ms 4548 KB Output isn't correct
81 Incorrect 43 ms 4532 KB Output isn't correct
82 Incorrect 35 ms 4528 KB Output isn't correct
83 Correct 66 ms 4516 KB Output is correct
84 Incorrect 42 ms 4552 KB Output isn't correct
85 Incorrect 61 ms 4548 KB Output isn't correct
86 Correct 52 ms 4428 KB Output is correct
87 Incorrect 41 ms 4548 KB Output isn't correct
88 Correct 68 ms 4372 KB Output is correct
89 Correct 46 ms 4388 KB Output is correct
90 Correct 55 ms 4416 KB Output is correct
91 Incorrect 48 ms 4428 KB Output isn't correct
92 Correct 61 ms 4480 KB Output is correct