Submission #1121289

#TimeUsernameProblemLanguageResultExecution timeMemory
1121289OmarAlimammadzadeTracks in the Snow (BOI13_tracks)C++17
100 / 100
573 ms119128 KiB
// author - alimammadzade

#include <bits/stdc++.h>
using namespace std;

const int N = 4001;
char c[N][N];
int dis[N][N], res, n, m, dx[] = { 0, 0, -1, 1 }, dy[] = { -1, 1, 0, 0 };

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    // system("cls"), freopen("in.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> c[i][j];
    deque<array<int, 2>> q;
    q.push_back({ 1, 1 });
    dis[1][1] = 1;
    while (!q.empty()) {
        auto [x, y] = q.front(); q.pop_front();
        res = max(res, dis[x][y]);
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 < nx and nx <= n and 0 < ny and ny <= m and !dis[nx][ny] and c[nx][ny] != '.')
                if (c[nx][ny] == c[x][y]) {
                    dis[nx][ny] = dis[x][y];
                    q.push_front({ nx, ny });
                }
                else {
                    dis[nx][ny] = dis[x][y] + 1;
                    q.push_back({ nx, ny });
                }
        }
    }
    cout << res;
}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:25:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   25 |             if (0 < nx and nx <= n and 0 < ny and ny <= m and !dis[nx][ny] and c[nx][ny] != '.')
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...