# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926707 | htphong0909 | Tracks in the Snow (BOI13_tracks) | C++17 | 83 ms | 12764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
void File() {
#define file "ZOO"
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
int n, m;
bool visited[1001][1001];
char arr[1001][1001];
vector<pair<int, int>> dif, nDif;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool canGo(int x, int y)
{
return (x <= n && y <= m && min(x, y) > 0 && arr[x][y] != '.' && !visited[x][y]);
}
void dfs(int x, int y)
{
visited[x][y] = true;
for (int i = 0; i < 4; i++)
{
int vx = x + dx[i];
int vy = y + dy[i];
if (canGo(vx, vy))
{
if (arr[vx][vy] == arr[x][y]) dfs(vx, vy);
else nDif.emplace_back(vx, vy);
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//File();
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> arr[i][j];
}
}
nDif.emplace_back(1, 1);
int ans = 0;
while (!nDif.empty())
{
ans++;
dif = nDif;
nDif.clear();
for (pair<int, int> cur : dif) dfs(cur.first, cur.second);
dif.clear();
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |