Submission #925950

# Submission time Handle Problem Language Result Execution time Memory
925950 2024-02-12T11:32:14 Z boris_mihov Mecho (IOI09_mecho) C++17
53 / 100
143 ms 6396 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>

typedef long long llong;
const int MAXN = 800 + 10;
const int INF  = 1e9;

int n, s;
char t[MAXN][MAXN];
int beeDist[MAXN][MAXN];
int myDist[MAXN][MAXN];
std::pair <int,int> delta[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
std::queue <std::pair <int,int>> q;

bool inside(int row, int col)
{
    return row >= 1 && row <= n && col >= 1 && col <= n;
}

bool check(int time)
{
    time *= s;
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = 1 ; j <= n ; ++j)
        {
            myDist[i][j] = INF;
            if (t[i][j] == 'M')
            {
                if (beeDist[i][j] <= time)
                {
                    return false;
                }

                myDist[i][j] = time;
                q.push({i, j});
            }
        }
    }

    while (q.size())
    {
        auto [row, col] = q.front();
        q.pop();        

        for (const auto &[dx, dy] : delta)
        {
            if (inside(row + dx, col + dy) && myDist[row][col] + 1 < beeDist[row + dx][col + dy] && t[row + dx][col + dy] != 'T' && myDist[row + dx][col + dy] == INF)
            {
                myDist[row + dx][col + dy] = myDist[row][col] + 1;
                q.push({row + dx, col + dy});
            }
        }
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = 1 ; j <= n ; ++j)
        {
            if (t[i][j] == 'D')
            {
                return (myDist[i][j] != INF);
            }
        }
    }

    assert(false);
}

void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = 1 ; j <= n ; ++j)
        {
            beeDist[i][j] = (t[i][j] == 'H' ? 0 : INF);
            if (t[i][j] == 'H')
            {
                q.push({i, j});
                beeDist[i][j] = 0;
            }
        }
    }

    while (q.size())
    {
        auto [row, col] = q.front();
        q.pop();

        for (const auto &[dx, dy] : delta)
        {
            if (inside(row + dx, col + dy) && t[row + dx][col + dy] != 'D' && t[row + dx][col + dy] != 'T' && beeDist[row + dx][col + dy] == INF)
            {
                beeDist[row + dx][col + dy] = beeDist[row][col] + s;
                q.push({row + dx, col + dy});
            }
        }
    }

    int l = -1, r = 3 * n, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }

    std::cout << l << '\n';
}

void input()
{
    std::cin >> n >> s;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> t[i] + 1;
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}

Compilation message

mecho.cpp: In function 'void input()':
mecho.cpp:120:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  120 |         std::cin >> t[i] + 1;
      |                     ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 69 ms 6240 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Incorrect 1 ms 4700 KB Output isn't correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 4616 KB Output is correct
15 Incorrect 1 ms 2396 KB Output isn't correct
16 Incorrect 1 ms 2648 KB Output isn't correct
17 Incorrect 1 ms 2392 KB Output isn't correct
18 Incorrect 1 ms 2396 KB Output isn't correct
19 Incorrect 1 ms 2396 KB Output isn't correct
20 Incorrect 1 ms 2396 KB Output isn't correct
21 Incorrect 1 ms 2648 KB Output isn't correct
22 Incorrect 1 ms 2652 KB Output isn't correct
23 Incorrect 1 ms 2652 KB Output isn't correct
24 Incorrect 1 ms 2652 KB Output isn't correct
25 Incorrect 1 ms 4700 KB Output isn't correct
26 Incorrect 2 ms 4696 KB Output isn't correct
27 Incorrect 1 ms 4700 KB Output isn't correct
28 Incorrect 1 ms 4700 KB Output isn't correct
29 Incorrect 1 ms 4700 KB Output isn't correct
30 Incorrect 1 ms 4700 KB Output isn't correct
31 Incorrect 1 ms 4700 KB Output isn't correct
32 Incorrect 1 ms 4700 KB Output isn't correct
33 Incorrect 9 ms 4956 KB Output isn't correct
34 Incorrect 14 ms 4956 KB Output isn't correct
35 Correct 16 ms 4956 KB Output is correct
36 Incorrect 12 ms 4956 KB Output isn't correct
37 Incorrect 19 ms 5064 KB Output isn't correct
38 Correct 21 ms 4952 KB Output is correct
39 Incorrect 14 ms 4956 KB Output isn't correct
40 Incorrect 23 ms 5100 KB Output isn't correct
41 Correct 28 ms 4956 KB Output is correct
42 Incorrect 17 ms 4952 KB Output isn't correct
43 Incorrect 27 ms 4956 KB Output isn't correct
44 Correct 32 ms 5152 KB Output is correct
45 Incorrect 21 ms 4964 KB Output isn't correct
46 Incorrect 34 ms 5188 KB Output isn't correct
47 Correct 42 ms 5208 KB Output is correct
48 Incorrect 24 ms 5384 KB Output isn't correct
49 Incorrect 39 ms 5464 KB Output isn't correct
50 Correct 52 ms 5212 KB Output is correct
51 Incorrect 29 ms 5464 KB Output isn't correct
52 Incorrect 46 ms 5468 KB Output isn't correct
53 Correct 59 ms 5592 KB Output is correct
54 Incorrect 36 ms 5724 KB Output isn't correct
55 Incorrect 60 ms 5724 KB Output isn't correct
56 Correct 70 ms 5720 KB Output is correct
57 Incorrect 42 ms 5976 KB Output isn't correct
58 Incorrect 68 ms 5980 KB Output isn't correct
59 Correct 90 ms 5976 KB Output is correct
60 Incorrect 46 ms 5976 KB Output isn't correct
61 Incorrect 87 ms 6184 KB Output isn't correct
62 Correct 89 ms 6192 KB Output is correct
63 Correct 81 ms 5976 KB Output is correct
64 Correct 131 ms 6184 KB Output is correct
65 Correct 143 ms 6184 KB Output is correct
66 Correct 97 ms 6024 KB Output is correct
67 Correct 89 ms 5980 KB Output is correct
68 Correct 40 ms 6236 KB Output is correct
69 Correct 32 ms 6236 KB Output is correct
70 Correct 33 ms 5976 KB Output is correct
71 Correct 38 ms 5980 KB Output is correct
72 Correct 27 ms 5980 KB Output is correct
73 Correct 20 ms 6236 KB Output is correct
74 Correct 47 ms 6236 KB Output is correct
75 Correct 61 ms 6236 KB Output is correct
76 Correct 55 ms 6232 KB Output is correct
77 Correct 46 ms 6232 KB Output is correct
78 Correct 55 ms 6288 KB Output is correct
79 Correct 38 ms 6232 KB Output is correct
80 Correct 45 ms 6232 KB Output is correct
81 Correct 56 ms 6236 KB Output is correct
82 Correct 45 ms 6232 KB Output is correct
83 Correct 62 ms 6236 KB Output is correct
84 Correct 68 ms 6396 KB Output is correct
85 Correct 51 ms 6240 KB Output is correct
86 Correct 60 ms 6236 KB Output is correct
87 Correct 64 ms 6236 KB Output is correct
88 Correct 57 ms 6232 KB Output is correct
89 Correct 57 ms 6236 KB Output is correct
90 Correct 60 ms 6232 KB Output is correct
91 Correct 66 ms 6232 KB Output is correct
92 Correct 63 ms 6236 KB Output is correct