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 <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int row, col;
cin>>row>>col;
char meadow[row][col];
int vis[row][col];
for(int i=0;i<row;i++){
fill(vis[i],vis[i]+col,0);
}
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cin>>meadow[i][j];
}
}
int numberoftimes=0;
if(meadow[0][0]=='.')return 0;
int dx[4] = {0, 0, -1, 1},dy[4] = {1, -1, 0, 0}; //dx and dy stores the way to get to the adjacent nodes
vis[0][0]=1;
int maxweight=-1;
//priority_queue<tuple<int, int, int>, vector<tuple<int, int, int> >, greater<tuple<int, int, int> > > q;
queue<tuple<int,int,int> > q;
//pair contains <y_coord, x_coord>
q.push(make_tuple(1,0, 0)); //push the starting node
while (!q.empty()) {
int weight=get<0>(q.front());
maxweight=max(maxweight,weight);
int y = get<1>(q.front());
int x = get<2>(q.front());
q.pop();
for (int i = 0; i < 4; i++) {
int new_y = y + dy[i], new_x = x + dx[i]; //adjacent nodes
if(new_y>=0 and new_y<row and new_x>=0 and new_x<col and (meadow[new_y][new_x]=='F' or meadow[new_y][new_x]=='R') and vis[new_y][new_x]==0){
if(meadow[new_y][new_x]==meadow[y][x]){
vis[new_y][new_x]=vis[y][x];
}
else{
vis[new_y][new_x]=vis[y][x]+1;
}
q.push(make_tuple(vis[new_y][new_x],new_y,new_x));
}
//check if new node is within bounds, not visited and reachable (code for if it is not)
}
//cout<<"y: "<<y<<" x: "<<x<<" vis: "<<vis[y][x]<<" currchar: "<<currchar<<" number: "<<number<<"\n";
}
/*
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cout<<vis[i][j]<<" ";
}
cout<<"\n";
}
*/
cout<<maxweight;
}
/*
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
cout<<vis[i][j]<<" ";
}
cout<<"\n";
}
*/
//cout<<numberoftimes;
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:18:9: warning: unused variable 'numberoftimes' [-Wunused-variable]
18 | int numberoftimes=0;
| ^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |