제출 #476977

#제출 시각아이디문제언어결과실행 시간메모리
476977asdf1234codingTracks in the Snow (BOI13_tracks)C++14
100 / 100
704 ms124108 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; #define ll long long #define MOD (ll) (1e9+7) int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; int n,m; string board[4000]; bool inBounds(int x, int y) { return (x>=0 && x<n && y>=0 && y<m && board[x][y]!='.'); } int main() { ios_base::sync_with_stdio(false); cin>>n>>m; //height n width m for(int i=0; i<n;i++) cin>>board[i]; vector<vector<int>> dist(n, vector<int>(m, 0)); int ans = 1; deque<pair<int,int>> q; dist[0][0] = 1; q.push_back({0,0}); while(!q.empty()) { pair<int,int> curr = q.front(); q.pop_front(); ans = max(ans, dist[curr.first][curr.second]); for(int i=0; i<4; i++) { int x = curr.first + dx[i]; int y = curr.second + dy[i]; if(inBounds(x,y) && dist[x][y] == 0) { if(board[curr.first][curr.second] == board[x][y]) { dist[x][y] = dist[curr.first][curr.second]; q.push_front({x,y}); } else { dist[x][y] = dist[curr.first][curr.second]+1; q.push_back({x,y}); } } } } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...