Submission #1018392

# Submission time Handle Problem Language Result Execution time Memory
1018392 2024-07-09T22:20:33 Z cryptobunny Mecho (IOI09_mecho) C++14
29 / 100
444 ms 13356 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int n, s, mx, my;

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

bool check(int t, vector<vector<char>> grid, vector<vector<int>> btime) {
    priority_queue<pair<int, pair<int, int>>> q;
    q.push({0, {mx, my}});
    vector<vector<bool>> vis(n, vector<bool>(n));
    vis[mx][my] = 1;
    while (!q.empty()) {
        auto tp = q.top();
        q.pop();
        if (grid[tp.second.first][tp.second.second] == 'D') {
            return true;
        }
        for (int i = 0; i < 4; i++) {
            int nx = dx[i] + tp.second.first;
            int ny = dy[i] + tp.second.second;
            if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
            if (grid[nx][ny] == 'T' || (btime[nx][ny] - t) * s <= -tp.first) continue;
            if (!vis[nx][ny]) {
                vis[nx][ny] = 1;
                q.push({tp.first - 1, {nx, ny}});
            }
        }
    }
    return false;
}

signed main() {
    cin >> n >> s;
    vector<vector<char>> grid(n, vector<char>(n));
    priority_queue<pair<int, pair<int, int>>> q;
    vector<vector<int>> btime(n, vector<int>(n, 0x3f3f3f3f));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> grid[i][j];
            if (grid[i][j] == 'H') {
                btime[i][j] = 0;
                q.push({0, {i, j}});
            }
            if (grid[i][j] == 'M') mx = i, my = j;
        }
    }
    while (!q.empty()) {
        auto tp = q.top();
        q.pop();
        if (btime[tp.second.first][tp.second.second] != -tp.first) continue;
        for (int i = 0; i < 4; i++) {
            int nx = dx[i] + tp.second.first;
            int ny = dy[i] + tp.second.second;
            if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
            if (grid[nx][ny] != 'G' && grid[nx][ny] != 'M') continue;
            if (-tp.first + 1 < btime[nx][ny]) {
                btime[nx][ny] = 1 - tp.first;
                q.push({-1 + tp.first, {nx, ny}});
            }
        }
    }

    int l = 0;
    int r = 1e9 + 1;
    while (l != r) {
        int mid = (l + r + 1)/2;
        if (check(mid, grid, btime)) {
            l = mid;
        }
        else {
            r = mid - 1;
        }
    }
    cout << l << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 Correct 0 ms 348 KB Output is correct
7 Correct 350 ms 12876 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 1 ms 436 KB Output isn't correct
14 Incorrect 1 ms 528 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 1 ms 432 KB Output isn't correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB Output isn't correct
20 Correct 1 ms 436 KB Output is correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Correct 1 ms 348 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Correct 1 ms 348 KB Output is correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 1 ms 484 KB Output isn't correct
28 Correct 1 ms 348 KB Output is correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Correct 1 ms 348 KB Output is correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Correct 1 ms 348 KB Output is correct
33 Incorrect 13 ms 2576 KB Output isn't correct
34 Correct 10 ms 2648 KB Output is correct
35 Correct 61 ms 2808 KB Output is correct
36 Incorrect 11 ms 3520 KB Output isn't correct
37 Correct 12 ms 3420 KB Output is correct
38 Correct 90 ms 3620 KB Output is correct
39 Incorrect 14 ms 4188 KB Output isn't correct
40 Correct 15 ms 4188 KB Output is correct
41 Correct 102 ms 4336 KB Output is correct
42 Incorrect 18 ms 5208 KB Output isn't correct
43 Correct 20 ms 5212 KB Output is correct
44 Correct 160 ms 5292 KB Output is correct
45 Incorrect 20 ms 5976 KB Output isn't correct
46 Correct 23 ms 5980 KB Output is correct
47 Correct 173 ms 6052 KB Output is correct
48 Incorrect 22 ms 7260 KB Output isn't correct
49 Correct 25 ms 7256 KB Output is correct
50 Correct 210 ms 7252 KB Output is correct
51 Incorrect 25 ms 8280 KB Output isn't correct
52 Correct 27 ms 8276 KB Output is correct
53 Correct 290 ms 8276 KB Output is correct
54 Incorrect 32 ms 9552 KB Output isn't correct
55 Correct 36 ms 9628 KB Output is correct
56 Correct 357 ms 9856 KB Output is correct
57 Incorrect 36 ms 11092 KB Output isn't correct
58 Correct 39 ms 11100 KB Output is correct
59 Correct 349 ms 11296 KB Output is correct
60 Incorrect 45 ms 12632 KB Output isn't correct
61 Correct 43 ms 12376 KB Output is correct
62 Correct 428 ms 12692 KB Output is correct
63 Correct 249 ms 12744 KB Output is correct
64 Correct 444 ms 12672 KB Output is correct
65 Correct 436 ms 12744 KB Output is correct
66 Incorrect 313 ms 12748 KB Output isn't correct
67 Incorrect 272 ms 12704 KB Output isn't correct
68 Correct 158 ms 12788 KB Output is correct
69 Correct 160 ms 12784 KB Output is correct
70 Correct 145 ms 12784 KB Output is correct
71 Correct 129 ms 12868 KB Output is correct
72 Incorrect 133 ms 12760 KB Output isn't correct
73 Incorrect 162 ms 13212 KB Output isn't correct
74 Correct 230 ms 13308 KB Output is correct
75 Correct 265 ms 13256 KB Output is correct
76 Correct 236 ms 13264 KB Output is correct
77 Correct 234 ms 13256 KB Output is correct
78 Incorrect 272 ms 13344 KB Output isn't correct
79 Correct 208 ms 13272 KB Output is correct
80 Correct 245 ms 13356 KB Output is correct
81 Correct 244 ms 13280 KB Output is correct
82 Correct 216 ms 13268 KB Output is correct
83 Correct 278 ms 13172 KB Output is correct
84 Correct 301 ms 13228 KB Output is correct
85 Correct 262 ms 13164 KB Output is correct
86 Correct 292 ms 13140 KB Output is correct
87 Correct 276 ms 13156 KB Output is correct
88 Correct 285 ms 13048 KB Output is correct
89 Correct 298 ms 13104 KB Output is correct
90 Correct 337 ms 13120 KB Output is correct
91 Correct 314 ms 13092 KB Output is correct
92 Correct 323 ms 13036 KB Output is correct