Submission #950870

# Submission time Handle Problem Language Result Execution time Memory
950870 2024-03-20T20:58:03 Z blackslex Mecho (IOI09_mecho) C++17
4 / 100
166 ms 6612 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] = 1, 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 + 1; 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') 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("-1"); return 0;
    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 0 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 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 97 ms 6472 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 Incorrect 0 ms 348 KB Output isn't correct
12 Incorrect 0 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 344 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Incorrect 1 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 0 ms 348 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 1 ms 348 KB Output isn't correct
25 Incorrect 1 ms 348 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 6 ms 1632 KB Output isn't correct
34 Incorrect 6 ms 1880 KB Output isn't correct
35 Incorrect 22 ms 1672 KB Output isn't correct
36 Incorrect 6 ms 1884 KB Output isn't correct
37 Incorrect 9 ms 1884 KB Output isn't correct
38 Incorrect 29 ms 1884 KB Output isn't correct
39 Incorrect 7 ms 2392 KB Output isn't correct
40 Incorrect 8 ms 2396 KB Output isn't correct
41 Incorrect 37 ms 2432 KB Output isn't correct
42 Incorrect 12 ms 2652 KB Output isn't correct
43 Incorrect 11 ms 2784 KB Output isn't correct
44 Incorrect 50 ms 2652 KB Output isn't correct
45 Incorrect 11 ms 3164 KB Output isn't correct
46 Incorrect 11 ms 3320 KB Output isn't correct
47 Incorrect 63 ms 3340 KB Output isn't correct
48 Incorrect 13 ms 3672 KB Output isn't correct
49 Incorrect 13 ms 3676 KB Output isn't correct
50 Incorrect 73 ms 3676 KB Output isn't correct
51 Incorrect 16 ms 4440 KB Output isn't correct
52 Incorrect 17 ms 4444 KB Output isn't correct
53 Incorrect 83 ms 4468 KB Output isn't correct
54 Incorrect 18 ms 4952 KB Output isn't correct
55 Incorrect 20 ms 5212 KB Output isn't correct
56 Incorrect 96 ms 4956 KB Output isn't correct
57 Incorrect 19 ms 5720 KB Output isn't correct
58 Incorrect 19 ms 5724 KB Output isn't correct
59 Incorrect 112 ms 5724 KB Output isn't correct
60 Incorrect 21 ms 6236 KB Output isn't correct
61 Incorrect 21 ms 6236 KB Output isn't correct
62 Incorrect 130 ms 6472 KB Output isn't correct
63 Incorrect 106 ms 6488 KB Output isn't correct
64 Incorrect 158 ms 6456 KB Output isn't correct
65 Incorrect 166 ms 6456 KB Output isn't correct
66 Incorrect 130 ms 6456 KB Output isn't correct
67 Correct 108 ms 6236 KB Output is correct
68 Incorrect 50 ms 6428 KB Output isn't correct
69 Incorrect 56 ms 6348 KB Output isn't correct
70 Incorrect 47 ms 6224 KB Output isn't correct
71 Incorrect 37 ms 6224 KB Output isn't correct
72 Incorrect 34 ms 6236 KB Output isn't correct
73 Incorrect 37 ms 6476 KB Output isn't correct
74 Incorrect 70 ms 6612 KB Output isn't correct
75 Incorrect 76 ms 6492 KB Output isn't correct
76 Incorrect 78 ms 6496 KB Output isn't correct
77 Incorrect 86 ms 6392 KB Output isn't correct
78 Correct 82 ms 6312 KB Output is correct
79 Incorrect 65 ms 6228 KB Output isn't correct
80 Incorrect 73 ms 6348 KB Output isn't correct
81 Incorrect 78 ms 6480 KB Output isn't correct
82 Incorrect 60 ms 6228 KB Output isn't correct
83 Incorrect 92 ms 6300 KB Output isn't correct
84 Incorrect 80 ms 6480 KB Output isn't correct
85 Incorrect 87 ms 6484 KB Output isn't correct
86 Incorrect 88 ms 6488 KB Output isn't correct
87 Incorrect 107 ms 6472 KB Output isn't correct
88 Incorrect 98 ms 6464 KB Output isn't correct
89 Incorrect 95 ms 6476 KB Output isn't correct
90 Incorrect 108 ms 6472 KB Output isn't correct
91 Incorrect 113 ms 6476 KB Output isn't correct
92 Incorrect 95 ms 6492 KB Output isn't correct