Submission #848108

#TimeUsernameProblemLanguageResultExecution timeMemory
848108upedMecho (IOI09_mecho)C++14
55 / 100
180 ms6368 KiB
#include<bits/stdc++.h> using namespace std; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main() { int n, s; cin >> n >> s; vector<vector<char>> f(n, vector<char>(n)); queue<pair<int, int>> q; vector<vector<int>> mt(n, vector<int>(n, INT32_MAX)); pair<int, int> start; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> f[i][j]; if (f[i][j] == 'M') { start = {i, j}; } else if (f[i][j] == 'H') { q.emplace(i, j); mt[i][j] = 0; } } } auto inside = [&](int i, int j) { return i >= 0 && i < n && j >= 0 && j < n && f[i][j] != 'T'; }; while (!q.empty()) { auto [i, j] = q.front(); q.pop(); for (int k = 0; k < 4; ++k) { int ni = i + dx[k]; int nj = j + dy[k]; if (!inside(ni, nj)) continue; if (mt[i][j] + 1 < mt[ni][nj]) { mt[ni][nj] = mt[i][j] + 1; q.emplace(ni, nj); } } } bool fl = false; int l = 0, r = 160000; while (r > l + 1) { while (!q.empty()) q.pop(); int mid = (l + r) / 2; vector<vector<int>> ms(n, vector<int>(n, INT32_MAX)); ms[start.first][start.second] = 0; bool good = false; q.emplace(start.first, start.second); while (!q.empty()) { auto [i, j] = q.front(); q.pop(); for (int k = 0; k < 4; ++k) { int ni = i + dx[k]; int nj = j + dy[k]; if (!inside(ni, nj)) continue; if (f[ni][nj] == 'D') { good = true; fl = true; break; } int steps = ms[i][j] + 1; bool possible = mid + (steps / s) < mt[ni][nj]; if (possible && steps < ms[ni][nj]) { ms[ni][nj] = steps; q.emplace(ni, nj); } } if (good) break; } if (good) { l = mid; } else { r = mid; } } if (fl) { cout << l; } else { cout << -1; } }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |         auto [i, j] = q.front();
      |              ^
mecho.cpp:55:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |             auto [i, j] = q.front();
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...