Submission #543870

#TimeUsernameProblemLanguageResultExecution timeMemory
543870timreizinMecho (IOI09_mecho)C++17
73 / 100
228 ms6888 KiB
#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 (forest[i + dx[k]][j + dy[k]] == 'D') { if (dist[i][j] / 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]}); } } else { 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]] != 'T') { 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 (stderr)

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:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     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:62:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     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;
      |                                                           ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...