Submission #638633

#TimeUsernameProblemLanguageResultExecution timeMemory
638633kakayoshiTracks in the Snow (BOI13_tracks)C++14
100 / 100
736 ms130148 KiB
#include <bits/stdc++.h> using namespace std; #define forw(i,a,b) for(ll i=a;i<=b;i++) #define forb(i,a,b) for(ll i=a;i>=b;i--) #define fi first #define se second #define pb push_back #define pu push #define all(a) a.begin(),a.end() #define getbit(mask,i) ((mask>>(i))&1) #define minimize(a,b) (a)=min((a),(b)) typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll maxN=5000+5; const ll mod=1e9+7; const ll oo=1e18; const int tx[4]={0,1,0,-1}; const int ty[4]={1,0,-1,0}; char a[maxN][maxN]; int n,m,ans,vis[maxN][maxN]; bool outmap(int x, int y) { if (1<=x && x<=n) if (1<=y && y<=m) return 0; return 1; } void solve() { cin>>n>>m; forw(i,1,n) forw(j,1,m) cin>>a[i][j]; deque<pii> p; vis[1][1]=1; ans=1; p.push_front({1,1}); while (p.size()) { int x=p.front().fi; int y=p.front().se; p.pop_front(); forw(i,0,3) { int xx=x+tx[i]; int yy=y+ty[i]; if (a[xx][yy]!='.' && !vis[xx][yy] && !outmap(xx,yy)) if (a[x][y]==a[xx][yy]) { vis[xx][yy]=vis[x][y]; p.push_front({xx,yy}); } else { vis[xx][yy]=vis[x][y]+1; ans=max(ans,vis[xx][yy]); p.push_back({xx,yy}); } } } cout<<ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); //freopen("bruh.inp","r",stdin); //freopen("bruh.out","w",stdout); solve(); return 0; }

Compilation message (stderr)

tracks.cpp: In function 'void solve()':
tracks.cpp:46:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   46 |             if (a[xx][yy]!='.' && !vis[xx][yy] && !outmap(xx,yy))
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...