Submission #848100

#TimeUsernameProblemLanguageResultExecution timeMemory
848100upedMecho (IOI09_mecho)C++14
60 / 100
177 ms7240 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); } } } // for (int i = 0; i < n; ++i) { // for (int j = 0; j < n; ++j) { // if (mt[i][j] == INT32_MAX) { // cout << '*' << ' '; // } else { // cout << mt[i][j] << ' '; // } // } // cout << '\n'; // } int l = -1, r = 16000; 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; 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; } } cout << l; }

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:64:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |             auto [i, j] = q.front();
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...