Submission #484129

#TimeUsernameProblemLanguageResultExecution timeMemory
484129nehasaneMecho (IOI09_mecho)C++14
26 / 100
363 ms10140 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 800; vector <string> field(MAX_N); bool bees_visited[MAX_N][MAX_N], mecho_visited[MAX_N][MAX_N]; int mecho_dis[MAX_N][MAX_N], bees_dis[MAX_N][MAX_N], eating_dis[MAX_N][MAX_N]; queue <pair <int, int>> mecho_q, bees_q; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; int n, s; bool valid_sq(int x, int y){ if (x >= 0 && x < n && y >= 0 && y < n && field[x][y] != 'T' && field[x][y] != 'H') return true; return false; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); cin >> n >> s; for (int i = 0; i < n; i++) cin >> field[i]; vector <pair <int, int>> hives; int startx, starty, home_x, home_y; //find Mecho's position for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (field[i][j] == 'M'){ startx = i; starty = j; }else if (field[i][j] == 'H'){ hives.push_back({i, j}); }else if (field[i][j] == 'D'){ home_x = i; home_y = j; } } } int l = 0, r = 2*n; while (l <= r){ int eating_time = (l + r) / 2; memset(bees_visited, false, sizeof(bees_visited)); memset(mecho_visited, false, sizeof(mecho_visited)); memset(bees_dis, 0, sizeof(bees_dis)); memset(mecho_dis, 0, sizeof(mecho_dis)); //move bees for (auto i : hives) bees_q.push({i.first, i.second}); while (!bees_q.empty()){ int x = bees_q.front().first, y = bees_q.front().second; bees_q.pop(); for (int i = 0; i < 4; i++){ int nx = x + dx[i], ny = y + dy[i]; if (valid_sq(nx, ny) && !bees_visited[nx][ny]){ if (eating_dis[x][y] < eating_time){ eating_dis[nx][ny] = eating_dis[x][y] + 1; }else bees_dis[nx][ny] = bees_dis[x][y] + 1; bees_q.push({nx, ny}); bees_visited[nx][ny] = true; } } } mecho_q.push({startx, starty}); while (!mecho_q.empty()){ int x = mecho_q.front().first, y = mecho_q.front().second; mecho_q.pop(); for (int i = 0; i < 4; i++){ int nx = x + dx[i], ny = y + dy[i]; if (valid_sq(nx, ny) && !mecho_visited[nx][ny] && (mecho_dis[x][y] + 1) / s < bees_dis[nx][ny]){ mecho_visited[nx][ny] = true; mecho_q.push({nx, ny}); mecho_dis[nx][ny] = mecho_dis[x][y] + 1; } } } if (mecho_visited[home_x][home_y]) l = eating_time + 1; else r = eating_time - 1; //empty both queues while (!bees_q.empty()) bees_q.pop(); while (!mecho_q.empty()) mecho_q.pop(); } cout << l - 1 << '\n'; }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:77:41: warning: 'home_y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |         if (mecho_visited[home_x][home_y])
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
mecho.cpp:77:41: warning: 'home_x' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...