Submission #716276

#TimeUsernameProblemLanguageResultExecution timeMemory
716276nima_aryanTracks in the Snow (BOI13_tracks)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #endif using i64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int H, W; cin >> H >> W; vector grid(H, vector<char>(W)); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> grid[i][j]; } } auto id = [&](int i, int j) { return W * i + j; }; auto di = [&](int i) { return make_pair(i / W, i % W); }; const int N = H * W; vector<vector<int>> graph(N); auto add_edge = [&](int a, int b) { graph[a].push_back(b); graph[b].push_back(a); }; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (j + 1 < W) { add_edge(id(i, j), id(i, j + 1)); } if (i + 1 < H) { add_edge(id(i, j), id(i + 1, j)); } } } auto get = [&](int node) { auto [i, j] = di(node); return grid[i][j]; }; const int inf = (int) 1e9; vector<int> dist(N, inf); deque<int> dq; auto add = [&](int u, int d, int ex = 0) { if (ex) { dq.push_back(u); } else { dq.push_front(u); } dist[u] = d + ex; }; add(0, 0); int ans = 0; while (!dq.empty()) { int node = dq.front(); dq.pop_front(); ans = max(ans, dist[node]); for (int neighbor : graph[node]) { if (dist[neighbor] < inf) { continue; } add(neighbor, dist[node], get(node) != get(neighbor)); } } cout << ans << '\n'; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:16:11: error: missing template arguments before 'grid'
   16 |    vector grid(H, vector<char>(W));
      |           ^~~~
tracks.cpp:19:17: error: 'grid' was not declared in this scope
   19 |          cin >> grid[i][j];
      |                 ^~~~
tracks.cpp: In lambda function:
tracks.cpp:45:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |       auto [i, j] = di(node);
      |            ^
tracks.cpp:46:14: error: 'grid' was not declared in this scope; did you mean 'id'?
   46 |       return grid[i][j];
      |              ^~~~
      |              id