Submission #793036

#TimeUsernameProblemLanguageResultExecution timeMemory
793036MODDITracks in the Snow (BOI13_tracks)C++14
84.69 / 100
2081 ms114648 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<long long, long long> pll; using namespace std; int n, m; char mat[4001][4001]; bool vis[4001][4001]; int dist[4001][4001], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; bool in_range(int i, int j){ if(i >= 0 && j >= 0 && i < n && j < m) return true; return false; } int main(){ cin>>n>>m; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin>>mat[i][j]; priority_queue<pair<int, pii>> q; q.push(mp(0, mp(0, 0))); int ans = 1; dist[0][0] = vis[0][0] = 1; while(!q.empty()){ pii at = q.top().second; q.pop(); ans = max(ans, dist[at.first][at.second]); for(int dir = 0; dir < 4; dir++){ int nx = at.first + dx[dir], ny = at.second + dy[dir]; if(in_range(nx, ny) && mat[nx][ny] != '.' && !vis[nx][ny]){ vis[nx][ny] = true; dist[nx][ny] = dist[at.first][at.second] + (mat[at.first][at.second] != mat[nx][ny]); q.push(mp(-dist[nx][ny], mp(nx,ny))); } } } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...