Submission #888333

#TimeUsernameProblemLanguageResultExecution timeMemory
888333alan_cTracks in the Snow (BOI13_tracks)C++17
100 / 100
349 ms101728 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 4000, x[4] = {0, 0, -1, 1}, y[4] = {-1, 1, 0, 0};
string t[N];
bitset<N> v[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w; cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> t[i];

  int ans = 1;
  struct node {
    int r, c, d;
  };
  deque<node> bfs;
  bfs.push_back({0, 0, 1});
  while (!bfs.empty()) {
    node n = bfs.front();
    bfs.pop_front();
    ans = max(ans, n.d);

    for (int i = 0; i < 4; i++) {
      int r = n.r + x[i], c = n.c + y[i];
      if (r >= 0 && r < h && c >= 0 && c < w && !v[r][c] && t[r][c] != '.') {
        if (t[r][c] == t[n.r][n.c])
          bfs.push_front({r, c, n.d});
        else
          bfs.push_back({r, c, n.d + 1});
        v[r][c] = 1;
      }
    }
  }
  cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...