Submission #950868

# Submission time Handle Problem Language Result Execution time Memory
950868 2024-03-20T20:56:36 Z blackslex Mecho (IOI09_mecho) C++17
4 / 100
194 ms 6572 KB
#include<bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;
using tp = tuple<int, int, int>;

const int cd[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int n, s, sx, sy, tx, ty;

int main() {
    scanf("%d %d", &n, &s);
    vector<string> c(n + 5);
    for (int i = 1; i <= n; i++) cin >> c[i], c[i] = " " + c[i];
    queue<pii> q;
    vector<vector<int>> d(n + 5, vector<int>(n + 5, 1e9));
    vector<vector<bool>> f(n + 5, vector<bool>(n + 5));
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (c[i][j] == 'M') sx = i, sy = j; else if (c[i][j] == 'H') d[i][j] = 0, q.emplace(i, j); else if (c[i][j] == 'D') tx = i, ty = j;
    while (!q.empty()) {
        auto [x, y] = q.front(); q.pop();
        if (f[x][y]) continue; f[x][y] = 1;
        for (int i = 0; i < 4; i++) {
            int nx = x + cd[i][0], ny = y + cd[i][1];
            if (nx <= 0 || nx > n || ny <= 0 || ny > n || c[nx][ny] == 'T') continue;
            if (d[nx][ny] > d[x][y] + 1) d[nx][ny] = d[x][y] + 1, q.emplace(nx, ny);
        }
    }
    auto bs = [&] (int val) {
        vector<vector<int>> d2(n + 5, vector<int>(n + 5, 1e9));
        vector<vector<bool>> f2(n + 5, vector<bool>(n + 5));
        queue<tp> cq; d2[sx][sy] = val; cq.emplace(sx, sy, 0);
        while (!cq.empty()) {
            auto [x, y, t] = cq.front(); cq.pop();
            if (f2[x][y]) continue; f2[x][y] = 1;
            int nt = t + 1, nts = (t + 1) % s;
            for (int i = 0; i < 4; i++) {
                int nx = x + cd[i][0], ny = y + cd[i][1];
                if (nx <= 0 || nx > n || ny <= 0 || ny > n || c[nx][ny] == 'T' || c[nx][ny] == 'M' || c[nx][ny] == 'D') continue;
                if (!nts) d2[nx][ny] = d2[x][y] + 1;
                else d2[nx][ny] = d2[x][y];
                if (d2[nx][ny] < d[nx][ny]) cq.emplace(nx, ny, nt);
            }
        }
        return d2[tx][ty] != 1e9;
    };
    int l = 0, r = 1e6, ans = -1;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (bs(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    printf("%d", ans);
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:20:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   20 |         if (f[x][y]) continue; f[x][y] = 1;
      |         ^~
mecho.cpp:20:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   20 |         if (f[x][y]) continue; f[x][y] = 1;
      |                                ^
mecho.cpp: In lambda function:
mecho.cpp:33:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   33 |             if (f2[x][y]) continue; f2[x][y] = 1;
      |             ^~
mecho.cpp:33:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   33 |             if (f2[x][y]) continue; f2[x][y] = 1;
      |                                     ^~
mecho.cpp: In function 'int main()':
mecho.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %d", &n, &s);
      |     ~~~~~^~~~~~~~~~~~~~~~~
# 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 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 97 ms 6484 KB Output isn't correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 1 ms 344 KB Output isn't correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 1 ms 348 KB Output isn't correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Incorrect 1 ms 348 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 2 ms 348 KB Output isn't correct
25 Incorrect 1 ms 600 KB Output isn't correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Incorrect 1 ms 348 KB Output isn't correct
28 Incorrect 1 ms 348 KB Output isn't correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Incorrect 1 ms 348 KB Output isn't correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Incorrect 1 ms 348 KB Output isn't correct
33 Incorrect 12 ms 1628 KB Output isn't correct
34 Incorrect 19 ms 1628 KB Output isn't correct
35 Incorrect 21 ms 1672 KB Output isn't correct
36 Incorrect 15 ms 1884 KB Output isn't correct
37 Incorrect 28 ms 1884 KB Output isn't correct
38 Incorrect 28 ms 2424 KB Output isn't correct
39 Incorrect 19 ms 2396 KB Output isn't correct
40 Incorrect 32 ms 2396 KB Output isn't correct
41 Incorrect 34 ms 2428 KB Output isn't correct
42 Incorrect 25 ms 2648 KB Output isn't correct
43 Incorrect 37 ms 2648 KB Output isn't correct
44 Incorrect 46 ms 2840 KB Output isn't correct
45 Incorrect 29 ms 3160 KB Output isn't correct
46 Incorrect 48 ms 3320 KB Output isn't correct
47 Incorrect 57 ms 3164 KB Output isn't correct
48 Incorrect 35 ms 3632 KB Output isn't correct
49 Incorrect 56 ms 3676 KB Output isn't correct
50 Incorrect 70 ms 3676 KB Output isn't correct
51 Incorrect 41 ms 4444 KB Output isn't correct
52 Incorrect 66 ms 4444 KB Output isn't correct
53 Incorrect 78 ms 4444 KB Output isn't correct
54 Incorrect 48 ms 4956 KB Output isn't correct
55 Incorrect 77 ms 5076 KB Output isn't correct
56 Incorrect 106 ms 5068 KB Output isn't correct
57 Incorrect 61 ms 5968 KB Output isn't correct
58 Incorrect 87 ms 5748 KB Output isn't correct
59 Incorrect 112 ms 5776 KB Output isn't correct
60 Incorrect 63 ms 6236 KB Output isn't correct
61 Incorrect 112 ms 6480 KB Output isn't correct
62 Incorrect 123 ms 6476 KB Output isn't correct
63 Incorrect 96 ms 6456 KB Output isn't correct
64 Incorrect 194 ms 6456 KB Output isn't correct
65 Incorrect 177 ms 6224 KB Output isn't correct
66 Incorrect 143 ms 6236 KB Output isn't correct
67 Correct 107 ms 6232 KB Output is correct
68 Incorrect 47 ms 6228 KB Output isn't correct
69 Incorrect 50 ms 6232 KB Output isn't correct
70 Incorrect 40 ms 6364 KB Output isn't correct
71 Incorrect 39 ms 6236 KB Output isn't correct
72 Incorrect 68 ms 6236 KB Output isn't correct
73 Incorrect 44 ms 6236 KB Output isn't correct
74 Incorrect 125 ms 6476 KB Output isn't correct
75 Incorrect 85 ms 6480 KB Output isn't correct
76 Incorrect 72 ms 6488 KB Output isn't correct
77 Incorrect 89 ms 6484 KB Output isn't correct
78 Correct 81 ms 6488 KB Output is correct
79 Incorrect 124 ms 6492 KB Output isn't correct
80 Incorrect 78 ms 6500 KB Output isn't correct
81 Incorrect 80 ms 6484 KB Output isn't correct
82 Incorrect 90 ms 6480 KB Output isn't correct
83 Incorrect 94 ms 6484 KB Output isn't correct
84 Incorrect 118 ms 6480 KB Output isn't correct
85 Incorrect 79 ms 6228 KB Output isn't correct
86 Incorrect 83 ms 6288 KB Output isn't correct
87 Incorrect 92 ms 6572 KB Output isn't correct
88 Incorrect 93 ms 6492 KB Output isn't correct
89 Incorrect 122 ms 6480 KB Output isn't correct
90 Incorrect 97 ms 6248 KB Output isn't correct
91 Incorrect 99 ms 6484 KB Output isn't correct
92 Incorrect 99 ms 6468 KB Output isn't correct