제출 #895544

#제출 시각아이디문제언어결과실행 시간메모리
895544123456321Tracks in the Snow (BOI13_tracks)C++17
0 / 100
303 ms234580 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int mod = 1000000007; int n,m; #define pb push_back #define mp make_pair vector<vector<pair<int,int>>> adj; void solve() { cin >> n >>m ; vector<string> snow(n); for(int i = 0;i<n;i++)cin >> snow[i]; deque<pair<int,int>> q; vector<vector<int>> vis(n,vector<int>(m,0)); vector<vector<int>> dist(n,vector<int>(m,1e9)); vector<vector<int>> parent(n,vector<int>(m,-1)); vector<vector<int>> dir = {{1,0},{-1,0},{0,1},{0,-1}}; q.push_back({0,0}); while(!q.empty()) { auto curr = q.front(); q.pop_front(); int x = curr.first; int y = curr.second; if(vis[x][y])continue; vis[x][y] = 1; for(auto d : dir) { int nx = x + d[0]; int ny = y + d[1]; if(nx < 0 || nx >= n || ny < 0 || ny >= m)continue; if(snow[nx][ny] == snow[x][y]) { if(dist[nx][ny] > dist[x][y]) { dist[nx][ny] = dist[x][y]; parent[nx][ny] = parent[x][y]; q.push_front({nx,ny}); } } else { if(dist[nx][ny] > dist[x][y] + 1) { dist[nx][ny] = dist[x][y] + 1; parent[nx][ny] = parent[x][y]; q.push_back({nx,ny}); } } } } int ans = 0; for(int i = 0;i<n;i++) { for(int j = 0;j<m;j++) { if(dist[i][j] == 1e9)continue; if(snow[i][j] == '1')continue; if(dist[i][j] > ans) { ans = dist[i][j]; } } } cout << ans << "\n"; return; } int main() { int tests = 1; //cin >> tests; int i = 1; while (i <= tests) { //cout << "Case #"<< i<< ": "; solve(); if(i!=tests)cout << "\n"; i++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...