Submission #1321714

#TimeUsernameProblemLanguageResultExecution timeMemory
1321714maniikkTracks in the Snow (BOI13_tracks)C++17
0 / 100
1295 ms1114112 KiB
#include <bits/stdc++.h> #pragma GCC Optimize("Ofast") using namespace std; #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) int depth[4005][4005]; int main() { fast_cin(); #ifndef ONLINE_JUDGE freopen("C:\\Personal\\dsa-prep\\input.txt", "r", stdin); freopen("C:\\Personal\\dsa-prep\\output.txt", "w", stdout); #endif int h, w; cin >> h >> w; vector<string> s; for (int i = 0; i < h; i++) { string temp; cin >> temp; s.emplace_back(temp); } using cell = pair<int, int>; deque<cell> q; depth[0][0] = 1; q.push_back({0, 0}); vector<cell> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; auto inside = [&](int x, int y) { return x >= 0 && x < h && y >= 0 && y < w && s[x][y] != '.'; }; int ans = 1; while (!q.empty()) { auto [x, y] = q.front(); q.pop_front(); ans = max(ans, depth[x][y]); for (auto [dx, dy] : dir) { int nx = x + dx, ny = y + dy; if (inside(nx, ny) && depth[nx][ny] == 0) { if (s[x][y] == s[nx][ny]) { depth[nx][ny] = depth[x][y]; q.push_front({nx, ny}); } else { depth[nx][ny] = depth[x][y] + 1; q.push_back({nx, ny}); } } } } cout << ans << endl; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("C:\\Personal\\dsa-prep\\input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen("C:\\Personal\\dsa-prep\\output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...