This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |