Submission #442010

#TimeUsernameProblemLanguageResultExecution timeMemory
442010iag99Tracks in the Snow (BOI13_tracks)C++17
23.23 / 100
2095 ms102164 KiB
#include<bits/stdc++.h> #define ll long long #define mod 998244353 using namespace std; int h,w; bool isfree(vector<vector<char>> grid, int x, int y) { if(x>=0 && x<h && y>=0 && y<w && grid[x][y]!='.') { return true; } return false; } int main() { cin>>h>>w; vector<vector<char>> grid(h, vector<char>(w)); for(int i=0; i<h; i++) { for(int j=0; j<w; j++) { cin>>grid[i][j]; } } deque<pair<int,int>> q; q.push_back({0,0}); vector<vector<int>> depth(h, vector<int>(w)); depth[0][0]=1; vector<int> dx={1,0,-1,0}; vector<int> dy={0,1,0,-1}; int ans=0; while(!q.empty()) { pair<int,int> cur=q.front(); q.pop_front(); ans=max(ans, depth[cur.first][cur.second]); for(int i=0; i<4; i++) { int x=cur.first+dx[i]; int y=cur.second+dy[i]; if(isfree(grid,x,y) && depth[x][y]==0) { if(grid[x][y]==grid[cur.first][cur.second]) { depth[x][y]=depth[cur.first][cur.second]; q.push_front({x,y}); } else { depth[x][y]=depth[cur.first][cur.second]+1; q.push_back({x,y}); } } } } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...