Submission #1126017

#TimeUsernameProblemLanguageResultExecution timeMemory
1126017KasymKTracks in the Snow (BOI13_tracks)C++20
100 / 100
1120 ms132688 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 4e3+5; int dis[N][N], dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; bool vis[N][N]; char c[N][N]; int main(){ int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) scanf(" %c", &c[i][j]), vis[i][j]=(c[i][j]=='.'?1:0); auto is = [&](int x, int y) -> bool { return (x>=1 and x<=n and y>=1 and y<=m and !vis[x][y]); }; deque<pii> dq; dq.pb({1, 1}), dis[1][1] = 1, vis[1][1] = 1; int answer = 0; while(!dq.empty()){ pii P = dq.front(); dq.pop_front(), umax(answer, dis[P.ff][P.ss]); for(int ad = 0; ad < 4; ++ad){ int x = P.ff+dx[ad], y = P.ss+dy[ad]; if(!is(x, y)) continue; if(c[x][y]==c[P.ff][P.ss]) dis[x][y]=dis[P.ff][P.ss], vis[x][y]=1, dq.push_front({x, y}); else dis[x][y]=dis[P.ff][P.ss]+1, vis[x][y]=1, dq.pb({x, y}); } } printf("%d\n", answer); return 0; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
tracks.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |             scanf(" %c", &c[i][j]), vis[i][j]=(c[i][j]=='.'?1:0);
      |             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...