Submission #470707

# Submission time Handle Problem Language Result Execution time Memory
470707 2021-09-05T07:48:55 Z dooompy Mecho (IOI09_mecho) C++17
4 / 100
43 ms 5504 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

bool tree[1005][1005];
int bees[1005][1005];
bool seen[1005][1005];
int n, s, sx, sy, dx, dy;

int mx[]{1, -1, 0, 0};
int my[]{0, 0, 1, -1};

struct bear {
    int x, y, time, move;
};

bool able(int time) {
    fill(&seen[0][0], &seen[0][0] + sizeof(seen) / sizeof(seen[0][0]), false);
    int curtime = time;

    // curtime can go into curtime+2 but must finish on curtime+3

    queue<bear> q;
    q.push({sx, sy, curtime+2, 0});
    seen[sx][sy] = true;

    while (!q.empty()) {
        auto cur = q.front(); q.pop();
        if (cur.x == dx && cur.y == dy) return true;
        
        if (seen[cur.x][cur.y]) continue;

        if (cur.move == s) {
            cur.time++;
            if (bees[cur.x][cur.y] < cur.time) {
                continue;
            }
            cur.move = 0;
        }

        seen[cur.x][cur.y] = true;

        for (int i = 0; i < 4; i++) {
            int newx = cur.x + mx[i], newy = cur.y + my[i];

            if (newx < 0 || newx >= n || newy < 0 || newy >= n || bees[newx][newy] < cur.time || tree[newx][newy] || seen[newx][newy]) continue;
            
            q.push({newx, newy, cur.time, cur.move+1});
        }
    }

    return false;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    cin >> n >> s;
    queue<pair<int, int>> q;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char c; cin>> c;
            if (c == 'T') tree[i][j] = true;
            if (c == 'M') {
                sx = i; sy = j;

            }
            if (c == 'D') {
                dx = i; dy = j;
            }
            if (c == 'H') {
                q.push({i, j});
                bees[i][j] = 1;
            }
        }
    }

    while (!q.empty()) {
        auto cur = q.front();
        q.pop();

        for (int i = 0; i < 4; i++) {
            int newx = cur.first + mx[i], newy = cur.second + my[i];
            if (newx < 0 || newx >= n || newy < 0 || newy >= n || bees[newx][newy] || tree[newx][newy]) continue;
            bees[newx][newy] = bees[cur.first][cur.second] + 1;
            q.push({newx, newy});
        }
    }

    int lo = 0, hi = 1e9;

    int biggest = -1;

    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (able(mid)) {
            biggest = mid;
            lo = mid + 1;
        } else {
            hi = mid - 1;
        }
    }

    cout << biggest;

}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1228 KB Output isn't correct
2 Incorrect 2 ms 1228 KB Output isn't correct
3 Incorrect 2 ms 1228 KB Output isn't correct
4 Incorrect 2 ms 1228 KB Output isn't correct
5 Incorrect 2 ms 1228 KB Output isn't correct
6 Incorrect 2 ms 1228 KB Output isn't correct
7 Incorrect 32 ms 5192 KB Output isn't correct
8 Correct 2 ms 1356 KB Output is correct
9 Incorrect 2 ms 1356 KB Output isn't correct
10 Incorrect 2 ms 1356 KB Output isn't correct
11 Incorrect 2 ms 1356 KB Output isn't correct
12 Incorrect 2 ms 1484 KB Output isn't correct
13 Incorrect 2 ms 1484 KB Output isn't correct
14 Correct 2 ms 1484 KB Output is correct
15 Incorrect 2 ms 1356 KB Output isn't correct
16 Incorrect 2 ms 1356 KB Output isn't correct
17 Incorrect 2 ms 1356 KB Output isn't correct
18 Incorrect 2 ms 1420 KB Output isn't correct
19 Incorrect 2 ms 1356 KB Output isn't correct
20 Incorrect 2 ms 1356 KB Output isn't correct
21 Incorrect 2 ms 1484 KB Output isn't correct
22 Incorrect 2 ms 1612 KB Output isn't correct
23 Incorrect 2 ms 1560 KB Output isn't correct
24 Incorrect 2 ms 1484 KB Output isn't correct
25 Incorrect 2 ms 1484 KB Output isn't correct
26 Incorrect 2 ms 1484 KB Output isn't correct
27 Incorrect 2 ms 1612 KB Output isn't correct
28 Incorrect 2 ms 1612 KB Output isn't correct
29 Incorrect 2 ms 1612 KB Output isn't correct
30 Incorrect 2 ms 1612 KB Output isn't correct
31 Incorrect 2 ms 1612 KB Output isn't correct
32 Incorrect 2 ms 1612 KB Output isn't correct
33 Incorrect 6 ms 3020 KB Output isn't correct
34 Incorrect 7 ms 3072 KB Output isn't correct
35 Incorrect 7 ms 3032 KB Output isn't correct
36 Incorrect 7 ms 3276 KB Output isn't correct
37 Incorrect 7 ms 3260 KB Output isn't correct
38 Incorrect 9 ms 3228 KB Output isn't correct
39 Incorrect 9 ms 3524 KB Output isn't correct
40 Incorrect 9 ms 3404 KB Output isn't correct
41 Incorrect 11 ms 3448 KB Output isn't correct
42 Incorrect 10 ms 3760 KB Output isn't correct
43 Incorrect 10 ms 3772 KB Output isn't correct
44 Incorrect 12 ms 3692 KB Output isn't correct
45 Incorrect 12 ms 3932 KB Output isn't correct
46 Incorrect 12 ms 3908 KB Output isn't correct
47 Incorrect 14 ms 3916 KB Output isn't correct
48 Incorrect 14 ms 4168 KB Output isn't correct
49 Incorrect 14 ms 4260 KB Output isn't correct
50 Incorrect 16 ms 4244 KB Output isn't correct
51 Incorrect 16 ms 4476 KB Output isn't correct
52 Incorrect 16 ms 4428 KB Output isn't correct
53 Incorrect 19 ms 4404 KB Output isn't correct
54 Incorrect 18 ms 4624 KB Output isn't correct
55 Incorrect 18 ms 4716 KB Output isn't correct
56 Incorrect 22 ms 4684 KB Output isn't correct
57 Incorrect 20 ms 4956 KB Output isn't correct
58 Incorrect 21 ms 4976 KB Output isn't correct
59 Incorrect 24 ms 4924 KB Output isn't correct
60 Incorrect 23 ms 5184 KB Output isn't correct
61 Incorrect 21 ms 5152 KB Output isn't correct
62 Incorrect 27 ms 5160 KB Output isn't correct
63 Incorrect 36 ms 5160 KB Output isn't correct
64 Incorrect 36 ms 5212 KB Output isn't correct
65 Incorrect 36 ms 5176 KB Output isn't correct
66 Incorrect 38 ms 5188 KB Output isn't correct
67 Correct 37 ms 5152 KB Output is correct
68 Incorrect 38 ms 5172 KB Output isn't correct
69 Incorrect 39 ms 5168 KB Output isn't correct
70 Incorrect 40 ms 5176 KB Output isn't correct
71 Incorrect 38 ms 5140 KB Output isn't correct
72 Incorrect 39 ms 5176 KB Output isn't correct
73 Incorrect 32 ms 5420 KB Output isn't correct
74 Incorrect 32 ms 5436 KB Output isn't correct
75 Incorrect 32 ms 5504 KB Output isn't correct
76 Incorrect 32 ms 5416 KB Output isn't correct
77 Incorrect 32 ms 5432 KB Output isn't correct
78 Correct 32 ms 5484 KB Output is correct
79 Incorrect 32 ms 5416 KB Output isn't correct
80 Incorrect 36 ms 5440 KB Output isn't correct
81 Incorrect 43 ms 5356 KB Output isn't correct
82 Incorrect 33 ms 5360 KB Output isn't correct
83 Incorrect 41 ms 5440 KB Output isn't correct
84 Incorrect 33 ms 5352 KB Output isn't correct
85 Incorrect 36 ms 5364 KB Output isn't correct
86 Incorrect 33 ms 5444 KB Output isn't correct
87 Incorrect 33 ms 5412 KB Output isn't correct
88 Incorrect 32 ms 5288 KB Output isn't correct
89 Incorrect 33 ms 5304 KB Output isn't correct
90 Incorrect 32 ms 5272 KB Output isn't correct
91 Incorrect 33 ms 5340 KB Output isn't correct
92 Incorrect 34 ms 5400 KB Output isn't correct