Submission #965777

# Submission time Handle Problem Language Result Execution time Memory
965777 2024-04-19T07:19:02 Z OIaspirant2307 Mecho (IOI09_mecho) C++17
0 / 100
33 ms 11868 KB
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
#define int long long
#define pi pair<int, int>
#define f first
#define s second
const int N = 805;
const int INF = 1e10;
vector<vector<char>> grid(N, vector<char>(N));
vector<vector<int>> vis(N, vector<int>(N, INF));
vector<vector<int>> v(N, vector<int>(N, INF));
vector<pi> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
vector<pi> bees;
pi mecho;
pi loc;
int n, m;
int steps;

bool ok(int i, int j, int v)
{
    return (i >= 0 && i < n && j >= 0 && j < m && vis[i][j] > v && grid[i][j] != 'T');
}

void bee_bfs()
{
    queue<pi> q;
    for (auto p : bees)
    {
        vis[p.f][p.s] = 0;
        q.push(p);
    }
    while (!q.empty())
    {
        auto p = q.front();
        q.pop();
        for (auto mv : moves)
        {
            int val = vis[p.f][p.s] + 1;
            if (ok(p.f + mv.f, p.s + mv.s, val))
            {
                vis[p.f + mv.f][p.s + mv.s] = val;
                q.push({p.f + mv.f, p.s + mv.s});
            }
        }
    }
}

void mecho_bfs()
{
    queue<pi> q;
    v[mecho.f][mecho.s] = 0;
    q.push(mecho);
    while (!q.empty())
    {
        auto p = q.front();
        q.pop();
        for (auto mv : moves)
        {
            int val = v[p.f][p.s] + 1;
            if (ok(p.f + mv.f, p.s + mv.s, val))
            {
                v[p.f + mv.f][p.s + mv.s] = val;
                q.push({p.f + mv.f, p.s + mv.s});
            }
        }
    }
}
bool issoke(int t)
{
    return (((v[loc.f][loc.s]) / steps) + t) < (vis[loc.f][loc.s]);
}

signed main()
{
    cin >> n >> steps;
    int m = n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> grid[i][j];
            if (grid[i][j] == 'M')
            {
                mecho.f = i;
                mecho.s = j;
            }
            else if (grid[i][j] == 'H')
            {
                bees.push_back({i, j});
            }
            else if (grid[i][j] == 'D')
            {
                loc.f = i;
                loc.s = j;
            }
        }
    }
    bee_bfs();
    mecho_bfs();
    if (!issoke(0))
    {
        cout << -1 << '\n';
        return 0;
    }
    int l = 0;
    int r = 1;
    while (issoke(r))
    {
        r *= 2;
    }
    while (l + 1 < r)
    {
        int m = (l + r) / 2;
        if (issoke(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }
    cout << l << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 11100 KB Output isn't correct
2 Incorrect 5 ms 11060 KB Output isn't correct
3 Incorrect 5 ms 11100 KB Output isn't correct
4 Incorrect 5 ms 11096 KB Output isn't correct
5 Incorrect 5 ms 11100 KB Output isn't correct
6 Incorrect 6 ms 11080 KB Output isn't correct
7 Incorrect 26 ms 11328 KB Output isn't correct
8 Correct 6 ms 11100 KB Output is correct
9 Incorrect 5 ms 11100 KB Output isn't correct
10 Incorrect 5 ms 11172 KB Output isn't correct
11 Incorrect 6 ms 11100 KB Output isn't correct
12 Incorrect 6 ms 11100 KB Output isn't correct
13 Incorrect 5 ms 11100 KB Output isn't correct
14 Incorrect 6 ms 11112 KB Output isn't correct
15 Incorrect 6 ms 11100 KB Output isn't correct
16 Incorrect 5 ms 11100 KB Output isn't correct
17 Incorrect 6 ms 11096 KB Output isn't correct
18 Incorrect 5 ms 11096 KB Output isn't correct
19 Incorrect 6 ms 11100 KB Output isn't correct
20 Incorrect 6 ms 11100 KB Output isn't correct
21 Incorrect 6 ms 11096 KB Output isn't correct
22 Incorrect 5 ms 11096 KB Output isn't correct
23 Incorrect 6 ms 11216 KB Output isn't correct
24 Incorrect 6 ms 11220 KB Output isn't correct
25 Incorrect 6 ms 11100 KB Output isn't correct
26 Incorrect 6 ms 11100 KB Output isn't correct
27 Incorrect 5 ms 11100 KB Output isn't correct
28 Incorrect 6 ms 11100 KB Output isn't correct
29 Incorrect 6 ms 11100 KB Output isn't correct
30 Incorrect 5 ms 11100 KB Output isn't correct
31 Incorrect 6 ms 11100 KB Output isn't correct
32 Incorrect 6 ms 11100 KB Output isn't correct
33 Incorrect 9 ms 11332 KB Output isn't correct
34 Incorrect 10 ms 11356 KB Output isn't correct
35 Incorrect 10 ms 11368 KB Output isn't correct
36 Incorrect 12 ms 11352 KB Output isn't correct
37 Incorrect 11 ms 11396 KB Output isn't correct
38 Incorrect 11 ms 11356 KB Output isn't correct
39 Incorrect 13 ms 11372 KB Output isn't correct
40 Incorrect 12 ms 11356 KB Output isn't correct
41 Incorrect 12 ms 11356 KB Output isn't correct
42 Incorrect 14 ms 11472 KB Output isn't correct
43 Incorrect 16 ms 11868 KB Output isn't correct
44 Incorrect 13 ms 11352 KB Output isn't correct
45 Incorrect 16 ms 11552 KB Output isn't correct
46 Incorrect 15 ms 11456 KB Output isn't correct
47 Incorrect 15 ms 11356 KB Output isn't correct
48 Incorrect 17 ms 11356 KB Output isn't correct
49 Incorrect 19 ms 11356 KB Output isn't correct
50 Incorrect 17 ms 11352 KB Output isn't correct
51 Incorrect 23 ms 11356 KB Output isn't correct
52 Incorrect 19 ms 11356 KB Output isn't correct
53 Incorrect 19 ms 11612 KB Output isn't correct
54 Incorrect 21 ms 11356 KB Output isn't correct
55 Incorrect 21 ms 11612 KB Output isn't correct
56 Incorrect 21 ms 11380 KB Output isn't correct
57 Incorrect 24 ms 11448 KB Output isn't correct
58 Incorrect 24 ms 11608 KB Output isn't correct
59 Incorrect 24 ms 11612 KB Output isn't correct
60 Incorrect 28 ms 11548 KB Output isn't correct
61 Incorrect 26 ms 11608 KB Output isn't correct
62 Incorrect 27 ms 11700 KB Output isn't correct
63 Incorrect 33 ms 11600 KB Output isn't correct
64 Incorrect 26 ms 11604 KB Output isn't correct
65 Incorrect 26 ms 11612 KB Output isn't correct
66 Incorrect 26 ms 11540 KB Output isn't correct
67 Incorrect 27 ms 11560 KB Output isn't correct
68 Incorrect 26 ms 11624 KB Output isn't correct
69 Incorrect 26 ms 11448 KB Output isn't correct
70 Incorrect 26 ms 11612 KB Output isn't correct
71 Incorrect 26 ms 11612 KB Output isn't correct
72 Incorrect 27 ms 11612 KB Output isn't correct
73 Incorrect 27 ms 11568 KB Output isn't correct
74 Incorrect 28 ms 11752 KB Output isn't correct
75 Incorrect 26 ms 11616 KB Output isn't correct
76 Incorrect 30 ms 11644 KB Output isn't correct
77 Incorrect 27 ms 11608 KB Output isn't correct
78 Incorrect 26 ms 11612 KB Output isn't correct
79 Incorrect 26 ms 11608 KB Output isn't correct
80 Incorrect 26 ms 11612 KB Output isn't correct
81 Incorrect 26 ms 11496 KB Output isn't correct
82 Incorrect 26 ms 11612 KB Output isn't correct
83 Incorrect 27 ms 11676 KB Output isn't correct
84 Incorrect 30 ms 11800 KB Output isn't correct
85 Incorrect 26 ms 11636 KB Output isn't correct
86 Incorrect 26 ms 11600 KB Output isn't correct
87 Incorrect 27 ms 11612 KB Output isn't correct
88 Incorrect 31 ms 11656 KB Output isn't correct
89 Incorrect 27 ms 11612 KB Output isn't correct
90 Incorrect 27 ms 11560 KB Output isn't correct
91 Incorrect 27 ms 11612 KB Output isn't correct
92 Incorrect 26 ms 11760 KB Output isn't correct