| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1321714 | maniikk | Tracks in the Snow (BOI13_tracks) | C++17 | 1295 ms | 1114112 KiB |
#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int depth[4005][4005];
int main()
{
fast_cin();
#ifndef ONLINE_JUDGE
freopen("C:\\Personal\\dsa-prep\\input.txt", "r", stdin);
freopen("C:\\Personal\\dsa-prep\\output.txt", "w", stdout);
#endif
int h, w;
cin >> h >> w;
vector<string> s;
for (int i = 0; i < h; i++)
{
string temp;
cin >> temp;
s.emplace_back(temp);
}
using cell = pair<int, int>;
deque<cell> q;
depth[0][0] = 1;
q.push_back({0, 0});
vector<cell> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
auto inside = [&](int x, int y)
{
return x >= 0 && x < h && y >= 0 && y < w && s[x][y] != '.';
};
int ans = 1;
while (!q.empty())
{
auto [x, y] = q.front();
q.pop_front();
ans = max(ans, depth[x][y]);
for (auto [dx, dy] : dir)
{
int nx = x + dx, ny = y + dy;
if (inside(nx, ny) && depth[nx][ny] == 0)
{
if (s[x][y] == s[nx][ny])
{
depth[nx][ny] = depth[x][y];
q.push_front({nx, ny});
}
else
{
depth[nx][ny] = depth[x][y] + 1;
q.push_back({nx, ny});
}
}
}
}
cout << ans << endl;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
