제출 #1251691

#제출 시각아이디문제언어결과실행 시간메모리
1251691kunzaZa183Tracks in the Snow (BOI13_tracks)C++20
78.13 / 100
963 ms1114112 KiB
#include <bits/stdc++.h>
using namespace std;
const short mn = 4000;
short vvi[mn][mn];
char vs[mn][mn + 1];
short n, m;
short ct = 0;
vector<pair<short, short>> newones, new2;

const short dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
void flood(short x, short y) {
  vvi[x][y] = ct;
  // cout << x << " " << y << "\n";
  for (short i = 0; i < 4; i++) {
    short 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]) {
          vvi[nx][ny] = ct;
          flood(nx, ny);
        } else {
          new2.push_back({nx, ny});
        }
      }
    }
  }
};
signed main() {
  // cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  for (short i = 0; i < n; i++)
    cin >> vs[i];

  newones.push_back({0, 0});

  while (!newones.empty()) {
    ct++;

    for (auto [x, y] : newones) {
      flood(x, y);
    }

    new2.swap(newones);
    new2.clear();
  }

  short 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...