Submission #1251697

#TimeUsernameProblemLanguageResultExecution timeMemory
1251697kunzaZa183Tracks in the Snow (BOI13_tracks)C++20
100 / 100
683 ms217096 KiB
#include <bits/stdc++.h>
using namespace std;
const int mn = 4000;
int vvi[mn][mn];
char vs[mn][mn + 1];
int n, m;
int ct = 0;
vector<pair<int, int>> newones, new2;

signed main() {
  // cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> vs[i];

  deque<array<int, 3>> dai3;
  dai3.push_back({1, 0, 0});

  const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
  while (!dai3.empty()) {
    auto [w, x, y] = dai3.front();
    dai3.pop_front();

    if (vvi[x][y] != 0) {
      continue;
    }

    vvi[x][y] = w;

    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
        if (vvi[nx][ny] == 0 && vs[nx][ny] != '.') {
          if (vs[nx][ny] == vs[x][y]) {
            dai3.push_front({w, nx, ny});
          } else {
            dai3.push_back({w + 1, nx, ny});
          }
        }
      }
    }
  }

  int maxi = 0;
  for (auto &a : vvi)
    for (auto b : a)
      maxi = max(maxi, b);
  cout << maxi << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...