# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101449 | rocketninja7 | Tracks in the Snow (BOI13_tracks) | C++14 | 2059 ms | 106048 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
pair<int, int> dir[]={make_pair(0, -1), make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0)};
int main(){
int H, W;
scanf("%d%d", &H, &W);
char grid[H][W+1];
for(int i=0;i<H;i++){
scanf("%s", &grid[i]);
}
int dist[H][W];
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
dist[i][j]=-1;
}
}
dist[0][0]=1;
priority_queue<pair<int, pair<int, int> > > proc;
proc.push(make_pair(-1, make_pair(0, 0)));
while(!proc.empty()){
int x=proc.top().second.first, y=proc.top().second.second;
proc.pop();
for(int i=0;i<4;i++){
if(x+dir[i].first>-1&&x+dir[i].first<H&&y+dir[i].second>-1&&y+dir[i].second<W){
if(grid[x+dir[i].first][y+dir[i].second]!='.'){
if(dist[x+dir[i].first][y+dir[i].second]==-1){
if(grid[x+dir[i].first][y+dir[i].second]==grid[x][y]){
dist[x+dir[i].first][y+dir[i].second]=dist[x][y];
}
else{
dist[x+dir[i].first][y+dir[i].second]=dist[x][y]+1;
}
proc.push(make_pair(-dist[x+dir[i].first][y+dir[i].second], make_pair(x+dir[i].first, y+dir[i].second)));
}
}
}
}
}
int ans=1;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
ans=max(ans, dist[i][j]);
}
}
printf("%d", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |