# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854113 | nhatvpm | Tracks in the Snow (BOI13_tracks) | C++17 | 547 ms | 124000 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO(string name) {
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
void solve(){
int n,m,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
cin>>n>>m;
string grid[n];
for (int i=0;i<n;i++) cin>>grid[i];
deque<pair<int,int>> q;
vector<vector<int>> dis(n,vector<int>(m,0));
dis[0][0]=1;
int res=0;
q.push_front({0,0});
while (!q.empty()){
int x=q.front().first,y=q.front().second;
res=max(res,dis[x][y]);
q.pop_front();
for (int i=0;i<4;i++){
int r=x+dx[i],c=y+dy[i];
if (r>=0&&r<n&&c>=0&&c<m&&grid[r][c]!='.'&&dis[r][c]==0){
int w=grid[r][c]!=grid[x][y]?1:0;
dis[r][c]=dis[x][y]+w;
if (w==1) q.push_back({r,c});
else q.push_front({r,c});
}
}
}
cout<<res;
}
int main(){
//setIO("");
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc=1;
//cin>>tc;
while (tc--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |