Submission #1247839

#TimeUsernameProblemLanguageResultExecution timeMemory
1247839menkhTracks in the Snow (BOI13_tracks)C++17
100 / 100
976 ms119052 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int n, m, depth[4000][4000], answer = 1; char snow[4000][4000]; bool inside(int x, int y) { return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.'); } void solve() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) scanf(" %c", &snow[i][j]); } deque<pair<int, int>> q; q.push_back({0, 0}); depth[0][0] = 1; while (!q.empty()) { pair<int, int> c = q.front(); q.pop_front(); answer = max(answer, depth[c.first][c.second]); for (int i = 0; i < 4; i++) { int x = c.first + dx[i], y = c.second + dy[i]; if (inside(x, y) && depth[x][y] == 0) { if (snow[x][y] == snow[c.first][c.second]) { depth[x][y] = depth[c.first][c.second]; q.push_front({x, y}); } else { depth[x][y] = depth[c.first][c.second] + 1; q.push_back({x, y}); } } } } printf("%d", answer); } int main() { solve(); }

Compilation message (stderr)

tracks.cpp: In function 'void solve()':
tracks.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:18:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         for (int j = 0; j < m; j++) scanf(" %c", &snow[i][j]);
      |                                     ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...