Submission #442013

#TimeUsernameProblemLanguageResultExecution timeMemory
442013iag99Tracks in the Snow (BOI13_tracks)C++17
8.75 / 100
12 ms16460 KiB
#include<bits/stdc++.h> #define ll long long #define mod 998244353 using namespace std; int h,w; int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1}; int depth[4000][4000], ans = 1; string grid[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() { iostream::sync_with_stdio(false); cin.tie(0); 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.size()) { 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...