Submission #1120858

#TimeUsernameProblemLanguageResultExecution timeMemory
1120858vjudge1Tracks in the Snow (BOI13_tracks)C++14
0 / 100
1185 ms1048576 KiB
// author - alimammadzade

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

const int N = 4001;
char c[N][N];
int dx[] = { -1, 1, 0, 0 }, dy[] = { 0, 0, -1, 1 }, n, m, cur;
bool vis[N][N];
void dfs(int x, int y, vector<array<int, 2>>& res) {
    vis[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx == 0 or nx > n or ny == 0 or ny > n or c[nx][ny] == '.' or vis[nx][ny]) continue;
        if (c[nx][ny] != c[x][y]) res.push_back({ nx, ny });
        else dfs(nx, ny, res);
    }
}

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];
    vector<array<int, 2>> temp, temp1;
    dfs(1, 1, temp);
    while (!temp.empty()) {
        cur++;
        temp1.clear();
        while (!temp.empty()) {
            auto [x, y] = temp.back(); temp.pop_back();
            dfs(x, y, temp1);
        }
        temp = temp1;
    }
    cout << cur;
}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:32:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |             auto [x, y] = temp.back(); temp.pop_back();
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...