Submission #862289

#TimeUsernameProblemLanguageResultExecution timeMemory
862289blackslexTracks in the Snow (BOI13_tracks)C++17
100 / 100
406 ms133296 KiB
#include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int N = 4005, cd[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int n, m, d[N][N], mx = 1; char c[N][N]; deque<pii> q; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", c[i]); d[0][0] = 1; q.emplace_back(0, 0); while (!q.empty()) { int x, y; tie(x, y) = q.front(); q.pop_front(); mx = max(mx, d[x][y]); for (int i = 0; i < 4; i++) { int nx = x + cd[i][0], ny = y + cd[i][1]; if (nx < 0 || nx >= n || ny < 0 || ny >= m || c[nx][ny] == '.' || d[nx][ny]) continue; if (c[nx][ny] == c[x][y]) d[nx][ny] = d[x][y], q.emplace_front(nx, ny); else d[nx][ny] = d[x][y] + 1, q.emplace_back(nx, ny); } } printf("%d", mx); }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  for (int i = 0; i < n; i++) scanf("%s", c[i]);
      |                              ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...