Submission #543949

# Submission time Handle Problem Language Result Execution time Memory
543949 2022-03-31T17:01:33 Z timreizin Mecho (IOI09_mecho) C++17
0 / 100
25 ms 21284 KB
#include <iostream>
#include <vector>
#include <array>
#include <numeric>
#include <cassert>
#include <tuple>
#include <queue>

using namespace std;

using ll = long long;

const int INF = 1e9;

const array<int, 4> dx{1, -1, 0, 0}, dy{0, 0, 1, -1};

bool check(int w, int s, vector<string> &forest, vector<vector<int>> &beeD)
{
    vector<vector<int>> dist(beeD.size(), vector<int>(beeD.size(), INF));
    queue<pair<int, int>> q;
    for (int i = 0; i < beeD.size(); ++i)
    {
        for (int j = 0; j < beeD.size(); ++j)
        {
            if (forest[i][j] == 'M')
            {
                if (beeD[i][j] <= w) return false;
                dist[i][j] = 0;
                q.push({i, j});
            }
        }
    }
    while (!q.empty())
    {
        auto [i, j] = q.front();
        q.pop();
        for (int k = 0; k < 4; ++k)
        {
            if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
            {
                if (dist[i + dx[k]][j + dy[k]] > dist[i][j] + 1 && forest[i + dx[k]][j + dy[k]] != 'T')
                {
                    if ((dist[i][j] + 1) / s + w < beeD[i + dx[k]][j + dy[k]])
                    {
                        dist[i + dx[k]][j + dy[k]] = dist[i][j] + 1;
                        q.push({i + dx[k], j + dy[k]});
                    }
                }
            }
        }
    }
    for (int i = 0; i < beeD.size(); ++i) for (int j = 0; j < beeD.size(); ++j) if (forest[i][j] == 'D') return dist[i][j] != INF;
    return false;
}

int main()
{
    freopen("/Users/timreizin/Downloads/mecho.012.in", "r", stdin);
    cin.tie(0)->sync_with_stdio(0);
    int n, s;
    cin >> n >> s;
    vector<string> forest(n);
    for (string &i : forest) cin >> i;
    vector<vector<int>> beeD(n, vector<int>(n, INF));
    queue<pair<int, int>> q;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (forest[i][j] == 'H')
            {
                beeD[i][j] = 0;
                q.push({i, j});
            }
        }
    }
    while (!q.empty())
    {
        auto [i, j] = q.front();
        q.pop();
        for (int k = 0; k < 4; ++k)
        {
            if (i + dx[k] >= 0 && i + dx[k] < n && j + dy[k] >= 0 && j + dy[k] < n)
            {
                if (beeD[i + dx[k]][j + dy[k]] > beeD[i][j] + 1 && (forest[i + dx[k]][j + dy[k]] == 'G' || forest[i + dx[k]][j + dy[k]] == 'M'))
                {
                    beeD[i + dx[k]][j + dy[k]] = beeD[i][j] + 1;
                    q.push({i + dx[k], j + dy[k]});
                }
            }
        }
    }
    int l = 0, r = n * n;
    while (l < r)
    {
        int m = (l + r) >> 1;
        if (check(m, s, forest, beeD)) l = m + 1;
        else r = m;
    }
    cout << l - 1;
    return 0;
}

Compilation message

mecho.cpp: In function 'bool check(int, int, std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::vector<int> >&)':
mecho.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < beeD.size(); ++i)
      |                     ~~^~~~~~~~~~~~~
mecho.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int j = 0; j < beeD.size(); ++j)
      |                         ~~^~~~~~~~~~~~~
mecho.cpp:39:45: warning: comparison of integer expressions of different signedness: 'std::tuple_element<0, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
      |                                   ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:39:90: warning: comparison of integer expressions of different signedness: 'std::tuple_element<1, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
      |                                                                                ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < beeD.size(); ++i) for (int j = 0; j < beeD.size(); ++j) if (forest[i][j] == 'D') return dist[i][j] != INF;
      |                     ~~^~~~~~~~~~~~~
mecho.cpp:52:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < beeD.size(); ++i) for (int j = 0; j < beeD.size(); ++j) if (forest[i][j] == 'D') return dist[i][j] != INF;
      |                                                           ~~^~~~~~~~~~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     freopen("/Users/timreizin/Downloads/mecho.012.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 21240 KB Execution killed with signal 8
2 Runtime error 17 ms 21220 KB Execution killed with signal 8
3 Runtime error 16 ms 21204 KB Execution killed with signal 8
4 Runtime error 18 ms 21204 KB Execution killed with signal 8
5 Runtime error 17 ms 21204 KB Execution killed with signal 8
6 Runtime error 17 ms 21228 KB Execution killed with signal 8
7 Runtime error 17 ms 21256 KB Execution killed with signal 8
8 Runtime error 16 ms 21220 KB Execution killed with signal 8
9 Runtime error 22 ms 21204 KB Execution killed with signal 8
10 Runtime error 18 ms 21212 KB Execution killed with signal 8
11 Runtime error 17 ms 21204 KB Execution killed with signal 8
12 Runtime error 22 ms 21168 KB Execution killed with signal 8
13 Runtime error 21 ms 21280 KB Execution killed with signal 8
14 Runtime error 23 ms 21204 KB Execution killed with signal 8
15 Runtime error 19 ms 21204 KB Execution killed with signal 8
16 Runtime error 17 ms 21212 KB Execution killed with signal 8
17 Runtime error 17 ms 21204 KB Execution killed with signal 8
18 Runtime error 16 ms 21204 KB Execution killed with signal 8
19 Runtime error 16 ms 21204 KB Execution killed with signal 8
20 Runtime error 19 ms 21212 KB Execution killed with signal 8
21 Runtime error 17 ms 21200 KB Execution killed with signal 8
22 Runtime error 20 ms 21200 KB Execution killed with signal 8
23 Runtime error 17 ms 21204 KB Execution killed with signal 8
24 Runtime error 20 ms 21140 KB Execution killed with signal 8
25 Runtime error 20 ms 21220 KB Execution killed with signal 8
26 Runtime error 17 ms 21212 KB Execution killed with signal 8
27 Runtime error 17 ms 21172 KB Execution killed with signal 8
28 Runtime error 17 ms 21204 KB Execution killed with signal 8
29 Runtime error 18 ms 21192 KB Execution killed with signal 8
30 Runtime error 22 ms 21196 KB Execution killed with signal 8
31 Runtime error 18 ms 21224 KB Execution killed with signal 8
32 Runtime error 24 ms 21204 KB Execution killed with signal 8
33 Runtime error 17 ms 21252 KB Execution killed with signal 8
34 Runtime error 18 ms 21192 KB Execution killed with signal 8
35 Runtime error 17 ms 21276 KB Execution killed with signal 8
36 Runtime error 18 ms 21252 KB Execution killed with signal 8
37 Runtime error 18 ms 21204 KB Execution killed with signal 8
38 Runtime error 18 ms 21228 KB Execution killed with signal 8
39 Runtime error 18 ms 21204 KB Execution killed with signal 8
40 Runtime error 18 ms 21256 KB Execution killed with signal 8
41 Runtime error 18 ms 21200 KB Execution killed with signal 8
42 Runtime error 17 ms 21256 KB Execution killed with signal 8
43 Runtime error 17 ms 21232 KB Execution killed with signal 8
44 Runtime error 16 ms 21204 KB Execution killed with signal 8
45 Runtime error 18 ms 21204 KB Execution killed with signal 8
46 Runtime error 18 ms 21192 KB Execution killed with signal 8
47 Runtime error 19 ms 21164 KB Execution killed with signal 8
48 Runtime error 17 ms 21204 KB Execution killed with signal 8
49 Runtime error 20 ms 21152 KB Execution killed with signal 8
50 Runtime error 21 ms 21236 KB Execution killed with signal 8
51 Runtime error 18 ms 21204 KB Execution killed with signal 8
52 Runtime error 21 ms 21280 KB Execution killed with signal 8
53 Runtime error 17 ms 21192 KB Execution killed with signal 8
54 Runtime error 17 ms 21224 KB Execution killed with signal 8
55 Runtime error 17 ms 21204 KB Execution killed with signal 8
56 Runtime error 17 ms 21212 KB Execution killed with signal 8
57 Runtime error 18 ms 21196 KB Execution killed with signal 8
58 Runtime error 18 ms 21204 KB Execution killed with signal 8
59 Runtime error 18 ms 21216 KB Execution killed with signal 8
60 Runtime error 19 ms 21204 KB Execution killed with signal 8
61 Runtime error 20 ms 21204 KB Execution killed with signal 8
62 Runtime error 17 ms 21212 KB Execution killed with signal 8
63 Runtime error 18 ms 21204 KB Execution killed with signal 8
64 Runtime error 18 ms 21252 KB Execution killed with signal 8
65 Runtime error 18 ms 21272 KB Execution killed with signal 8
66 Runtime error 23 ms 21176 KB Execution killed with signal 8
67 Runtime error 17 ms 21204 KB Execution killed with signal 8
68 Runtime error 18 ms 21200 KB Execution killed with signal 8
69 Runtime error 17 ms 21204 KB Execution killed with signal 8
70 Runtime error 17 ms 21244 KB Execution killed with signal 8
71 Runtime error 18 ms 21164 KB Execution killed with signal 8
72 Runtime error 18 ms 21272 KB Execution killed with signal 8
73 Runtime error 19 ms 21204 KB Execution killed with signal 8
74 Runtime error 19 ms 21284 KB Execution killed with signal 8
75 Runtime error 18 ms 21212 KB Execution killed with signal 8
76 Runtime error 17 ms 21200 KB Execution killed with signal 8
77 Runtime error 18 ms 21204 KB Execution killed with signal 8
78 Runtime error 19 ms 21200 KB Execution killed with signal 8
79 Runtime error 17 ms 21252 KB Execution killed with signal 8
80 Runtime error 17 ms 21204 KB Execution killed with signal 8
81 Runtime error 22 ms 21220 KB Execution killed with signal 8
82 Runtime error 21 ms 21204 KB Execution killed with signal 8
83 Runtime error 19 ms 21204 KB Execution killed with signal 8
84 Runtime error 25 ms 21204 KB Execution killed with signal 8
85 Runtime error 18 ms 21204 KB Execution killed with signal 8
86 Runtime error 17 ms 21204 KB Execution killed with signal 8
87 Runtime error 16 ms 21204 KB Execution killed with signal 8
88 Runtime error 18 ms 21204 KB Execution killed with signal 8
89 Runtime error 18 ms 21196 KB Execution killed with signal 8
90 Runtime error 19 ms 21244 KB Execution killed with signal 8
91 Runtime error 23 ms 21204 KB Execution killed with signal 8
92 Runtime error 21 ms 21204 KB Execution killed with signal 8