답안 #543876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543876 2022-03-31T14:23:27 Z timreizin Mecho (IOI09_mecho) C++17
84 / 100
215 ms 6300 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')
            {
                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()
{
    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')
                {
                    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;
}

/*
7 3
TTTTTTT
TGGGGGT
TGGGGGT
MGGGGGD
TGGGGGT
TGGGGGT
TGHHGGT
*/

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:38: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]
   38 |             if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
      |                                   ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:38: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]
   38 |             if (i + dx[k] >= 0 && i + dx[k] < beeD.size() && j + dy[k] >= 0 && j + dy[k] < beeD.size())
      |                                                                                ~~~~~~~~~~^~~~~~~~~~~~~
mecho.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     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:51:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     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;
      |                                                           ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 105 ms 6184 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 8 ms 1436 KB Output is correct
34 Correct 10 ms 1444 KB Output is correct
35 Correct 23 ms 1436 KB Output is correct
36 Correct 13 ms 1748 KB Output is correct
37 Correct 12 ms 1748 KB Output is correct
38 Correct 34 ms 1748 KB Output is correct
39 Correct 16 ms 2216 KB Output is correct
40 Correct 14 ms 2212 KB Output is correct
41 Correct 67 ms 2148 KB Output is correct
42 Correct 17 ms 2588 KB Output is correct
43 Correct 19 ms 2588 KB Output is correct
44 Correct 51 ms 2584 KB Output is correct
45 Correct 18 ms 3100 KB Output is correct
46 Correct 21 ms 3040 KB Output is correct
47 Correct 68 ms 3052 KB Output is correct
48 Correct 26 ms 3644 KB Output is correct
49 Correct 37 ms 3580 KB Output is correct
50 Correct 77 ms 3604 KB Output is correct
51 Correct 29 ms 4172 KB Output is correct
52 Correct 32 ms 4180 KB Output is correct
53 Correct 88 ms 4136 KB Output is correct
54 Correct 37 ms 4848 KB Output is correct
55 Correct 35 ms 4784 KB Output is correct
56 Correct 148 ms 4760 KB Output is correct
57 Correct 38 ms 5488 KB Output is correct
58 Correct 41 ms 5412 KB Output is correct
59 Correct 125 ms 5420 KB Output is correct
60 Correct 48 ms 6112 KB Output is correct
61 Correct 55 ms 6092 KB Output is correct
62 Correct 198 ms 6128 KB Output is correct
63 Correct 137 ms 6112 KB Output is correct
64 Correct 194 ms 6116 KB Output is correct
65 Correct 215 ms 6108 KB Output is correct
66 Correct 150 ms 6184 KB Output is correct
67 Correct 144 ms 6088 KB Output is correct
68 Correct 74 ms 6120 KB Output is correct
69 Correct 68 ms 6140 KB Output is correct
70 Correct 64 ms 6176 KB Output is correct
71 Correct 56 ms 6140 KB Output is correct
72 Incorrect 57 ms 6108 KB Output isn't correct
73 Incorrect 88 ms 6124 KB Output isn't correct
74 Correct 72 ms 6132 KB Output is correct
75 Correct 84 ms 6124 KB Output is correct
76 Correct 81 ms 6152 KB Output is correct
77 Correct 83 ms 6136 KB Output is correct
78 Correct 97 ms 6152 KB Output is correct
79 Correct 67 ms 6136 KB Output is correct
80 Correct 75 ms 6160 KB Output is correct
81 Correct 90 ms 6300 KB Output is correct
82 Correct 80 ms 6124 KB Output is correct
83 Correct 102 ms 6128 KB Output is correct
84 Correct 84 ms 6132 KB Output is correct
85 Correct 83 ms 6124 KB Output is correct
86 Correct 87 ms 6168 KB Output is correct
87 Correct 89 ms 6132 KB Output is correct
88 Correct 105 ms 6180 KB Output is correct
89 Correct 92 ms 6124 KB Output is correct
90 Correct 96 ms 6140 KB Output is correct
91 Correct 107 ms 6136 KB Output is correct
92 Correct 94 ms 6128 KB Output is correct