Submission #962618

# Submission time Handle Problem Language Result Execution time Memory
962618 2024-04-14T03:17:32 Z novus677 Tracks in the Snow (BOI13_tracks) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <queue>
#include <tuple>

using namespace std;

int H, W;
char grid[4000][4000];
int visited[4000][4000];

int main() {
    cin >> H >> W;

    for (int i = 0; i < H; ++i) {
        string row;
        cin >> row;
        for (int j = 0; j < W; ++j) {
            grid[i][j] = row[j];
        }
    }

    deque<tuple<int, int>> q;
    q.push_front({0, 0});
    visited[0][0] = 1;
    while (!q.empty()) {
        auto [i, j] = q.front();
        q.pop_front();

        if (i > 0 && !visited[i - 1][j]) {
            if (grid[i - 1][j] == grid[i][j]) {
                visited[i - 1][j] = visited[i][j];
                q.push_front({i - 1, j});
            } else if (grid[i - 1][j] != '.') {
                visited[i - 1][j] = visited[i][j] + 1;
                q.push_back({i - 1, j});
            }
        }
        if (i < H - 1 && !visited[i + 1][j]) {
            if (grid[i + 1][j] == grid[i][j]) {
                visited[i + 1][j] = visited[i][j];
                q.push_front({i + 1, j});
            } else if (grid[i + 1][j] != '.') {
                visited[i + 1][j] = visited[i][j] + 1;
                q.push_back({i + 1, j});
            }
        }
        if (j > 0 && !visited[i][j - 1]) {
            if (grid[i][j - 1] == grid[i][j]) {
                visited[i][j - 1] = visited[i][j];
                q.push_front({i, j - 1});
            } else if (grid[i][j - 1] != '.') {
                visited[i][j - 1] = visited[i][j] + 1;
                q.push_back({i, j - 1});
            }
        }
        if (j < W - 1 && !visited[i][j + 1]) {
            if (grid[i][j + 1] == grid[i][j]) {
                visited[i][j + 1] = visited[i][j];
                q.push_front({i, j + 1});
            } else if (grid[i][j + 1] != '.') {
                visited[i][j + 1] = visited[i][j] + 1;
                q.push_back({i, j + 1});
            }
        }
    }

    int answer = 0;
    for (int i = 0; i < H; ++i) {
        answer = max(answer, *max_element(visited[i], visited[i] + W));
    }
    cout << answer << '\n';
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:26:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |         auto [i, j] = q.front();
      |              ^
tracks.cpp:69:31: error: 'max_element' was not declared in this scope
   69 |         answer = max(answer, *max_element(visited[i], visited[i] + W));
      |                               ^~~~~~~~~~~