# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
575987 | OnionEgg | Tracks in the Snow (BOI13_tracks) | C++17 | 594 ms | 231780 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.
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define ll long long
#define fas ios::sync_with_stdio(0); cout.tie(0); cin.tie(0)
#define el "\n"
#define fi first
#define se second
#define th third
#define taskName "codefuck"
using namespace std;
const ll mod = 1e9+7;
ll dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
ll n, m, depth[4005][4005], res;
string snow[4000];
bool inside(ll x, ll y)
{
return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}
void solve()
{
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> snow[i];
deque<pair<ll, ll>>q;
q.push_back({0, 0});
depth[0][0] = 1;
res = 1;
while(q.size())
{
pair<ll, ll> c = q.front();
q.pop_front();
res = max(res, depth[c.fi][c.se]);
for(int i = 0; i < 4; i++)
{
ll x = c.fi + dx[i], y = c.se + dy[i];
if(inside(x, y) && depth[x][y] == 0)
{
if(snow[x][y] == snow[c.fi][c.se])
{
depth[x][y] = depth[c.fi][c.se];
q.push_front({x, y});
}
else
{
depth[x][y] = depth[c.fi][c.se] + 1;
q.push_back({x, y});
}
}
}
}
cout << res;
}
int main()
{
fas;
if (fopen(taskName".inp", "r"))
{
freopen(taskName".inp", "r", stdin);
freopen(taskName".out", "w", stdout);
}
ll testcase = 1;
//cin >> testcase;
while(testcase--)
{
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |