제출 #1040469

#제출 시각아이디문제언어결과실행 시간메모리
1040469joelgun14Tracks in the Snow (BOI13_tracks)C++17
100 / 100
662 ms186456 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl "\n"
#define ll long long
#define mp make_pair
#define ins insert
#define lb lower_bound
#define pb push_back
#define ub upper_bound
#define lll __int128
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int main() {
  ios_base::sync_with_stdio(0); cin.tie(NULL);
  int n, m;
  cin >> n >> m; 
  char a[n + 5][m + 5];
  for(int i = 1; i <= n; ++i)
    for(int j = 1; j <= m; ++j)
      cin >> a[i][j];
  deque<pair<int, pair<int, int>>> bfs;
  bfs.push_back(mp(0, mp(1, 1)));
  bool vis[n + 5][m + 5];
  int res = 0;
  memset(vis, 0, sizeof(vis));
  vector<pair<int, int>> nxt = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  function<bool(int, int)> check = [&] (int x, int y) -> int {
    return x <= n && x >= 1 && y >= 1 && y <= m;
  };
  while(bfs.size()) {
    int d = bfs.front().fi, x = bfs.front().se.fi, y = bfs.front().se.se;
    bfs.pop_front();
    if(vis[x][y])
      continue;
    vis[x][y] = 1;
    res = max(res, d);
    // cout << x << " " << y << " " << d << endl;
    for(auto p : nxt) {
      if(check(x + p.fi, y + p.se) && !vis[x + p.fi][y + p.se] && a[x + p.fi][y + p.se] != '.') {
        if(a[x + p.fi][y + p.se] == a[x][y])
          bfs.push_front(mp(d, mp(x + p.fi, y + p.se)));
        else
          bfs.pb(mp(d + 1, mp(x + p.fi, y + p.se)));
      }
    }
  }
  cout << res + 1 << endl;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...