Submission #581490

#TimeUsernameProblemLanguageResultExecution timeMemory
581490Saeed_247Mecho (IOI09_mecho)C++14
47 / 100
255 ms12372 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void dout(string name, T arg) { cerr << name << " = " << arg << "\e[39m" << endl; } template<typename T1, typename... T2> void dout(string names, T1 arg, T2... args) { cerr << names.substr(0, names.find(',')) << " = " << arg << " | "; dout(names.substr(names.find(',') + 2), args...); } #define debug(...) cerr << "\e[91m" << "[" << __LINE__ << ":" << __func__ << "]=> ", dout(#__VA_ARGS__, __VA_ARGS__); const pair<int, int> dir[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const int N = 800; bool visited[N][N]; long long n, s; vector<vector<char>> arr; vector<pair<long long, long long>> hives; pair<long long, long long> m, d; queue<pair<long long, long long>> q; bool move(int x, int y) { return x >= 0 && y >= 0 && x < n && y < n; } bool check(long long tim, vector<vector<long long>>& dist, vector<vector<long long>>& swarm) { memset(visited, false, sizeof visited); while (q.size()) q.pop(); q.push(m); visited[m.first][m.second] = true; while (!q.empty()) { auto [x, y] = q.front(); if (q.front() == d) return true; q.pop(); for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && (arr[x + xx][y + yy] == 'G' || arr[x + xx][y + yy] == 'D') && !visited[x + xx][y + yy] && (dist[x + xx][y + yy] + tim < swarm[x + xx][y + yy] || (dist[x + xx][y + yy] + tim == swarm[x + xx][y + yy] && dist[d.first][d.second] == dist[x + xx][y + yy]))) { q.push({x + xx, y + yy}); visited[x + xx][y + yy] = true; } } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; arr.resize(n, vector<char> (n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> arr[i][j]; if (arr[i][j] == 'M') { m = {i, j}; } if (arr[i][j] == 'H') { hives.push_back({i, j}); } if (arr[i][j] == 'D') { d = {i, j}; } } } vector<vector<long long>> dist(n, vector<long long>(n, 1e18)), swarm(n, vector<long long>(n, 1e18)); dist[m.first][m.second] = 0; q.push(m); while (!q.empty()) { auto [x, y] = q.front(); q.pop(); for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && (arr[x + xx][y + yy] == 'G' || arr[x + xx][y + yy] == 'D') && dist[x + xx][y + yy] > dist[x][y] + 1) { dist[x + xx][y + yy] = dist[x][y] + 1; q.push({x + xx, y + yy}); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dist[i][j] = dist[i][j] / s + (dist[i][j] % s != 0); } } for (auto [x, y] : hives) { swarm[x][y] = 0; q.push({x, y}); } while (!q.empty()) { auto [x, y] = q.front(); q.pop(); for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && arr[x + xx][y + yy] == 'G' && swarm[x + xx][y + yy] > swarm[x][y] + 1) { swarm[x + xx][y + yy] = swarm[x][y] + 1; q.push({x + xx, y + yy}); } } long long l = 0, h = 1e9; while (h - l > 1) { long long mid = (h + l) / 2; if (check(mid, dist, swarm)) l = mid; else h = mid; } cout << l << '\n'; return 0; }

Compilation message (stderr)

mecho.cpp: In function 'bool check(long long int, std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&)':
mecho.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |         auto [x, y] = q.front();
      |              ^
mecho.cpp:34:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |         for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && (arr[x + xx][y + yy] == 'G' ||
      |                   ^
mecho.cpp: In function 'int main()':
mecho.cpp:67:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |         auto [x, y] = q.front();
      |              ^
mecho.cpp:69:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |         for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && (arr[x + xx][y + yy] == 'G' ||
      |                   ^
mecho.cpp:80:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |     for (auto [x, y] : hives) {
      |               ^
mecho.cpp:85:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   85 |         auto [x, y] = q.front();
      |              ^
mecho.cpp:87:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   87 |         for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && arr[x + xx][y + yy] == 'G' && swarm[x + xx][y + yy] > swarm[x][y] + 1) {
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...