Submission #442015

#TimeUsernameProblemLanguageResultExecution timeMemory
442015iag99Tracks in the Snow (BOI13_tracks)C++17
100 / 100
1536 ms118856 KiB
#include<bits/stdc++.h> #define ll long long #define mod 998244353 using namespace std; int h,w; vector<int> dx={1, -1, 0, 0}; vector<int> dy={0, 0, 1, -1}; int depth[4000][4000], ans = 1; char grid[4000][4000]; bool isfree(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; 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}); depth[0][0]=1; 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(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...