이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
deque<tuple<int,int,int> > q;
//pair contains <y_coord, x_coord>
q.push_front(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_front();
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];
q.push_front(make_tuple(vis[new_y][new_x],new_y,new_x));
}
else{
vis[new_y][new_x]=vis[y][x]+1;
q.push_back(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;
컴파일 시 표준 에러 (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... |