제출 #1061936

#제출 시각아이디문제언어결과실행 시간메모리
1061936sikai004Tracks in the Snow (BOI13_tracks)C++14
65 / 100
2096 ms97876 KiB
#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; queue<tuple<int, int,int,char> > q; //pair contains <y_coord, x_coord> q.push(make_tuple(0, 0,1,meadow[0][0])); //push the starting node while (!q.empty()) { int y = get<0>(q.front()); int x = get<1>(q.front()); int number = get<2>(q.front()); char currchar = get<3>(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')){ if(vis[new_y][new_x]==0){ if(meadow[new_y][new_x]!=currchar){ vis[new_y][new_x]=number+1; q.push(make_tuple(new_y,new_x,number+1,meadow[new_y][new_x])); //if(new_y==2 and new_x==1)cout<<"FUCK OFF"; //if(new_y==3 and new_x==7)cout<<"HI"<<number; } else{ vis[new_y][new_x]=number; q.push(make_tuple(new_y,new_x,number,meadow[new_y][new_x])); } } else if(meadow[new_y][new_x]==currchar and vis[new_y][new_x]>number){ vis[new_y][new_x]=number; q.push(make_tuple(new_y,new_x,number,meadow[new_y][new_x])); } else if(meadow[new_y][new_x]!=currchar and vis[new_y][new_x]>number+1){ vis[new_y][new_x]=number+1; q.push(make_tuple(new_y,new_x,number+1,meadow[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"; } */ int maxx=-1; for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ maxx=max(maxx,vis[i][j]); } //cout<<"\n"; } cout<<maxx; } /* 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...