# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443704 | BeanZ | Tracks in the Snow (BOI13_tracks) | C++14 | 2096 ms | 351472 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.
// I_Love_LPL 1y0m2d
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 4005;
long long mod = 1000007;
const int lim = 4e5 + 5;
const int lg = 20;
const int base = 311;
const long double eps = 1e-6;
ll nx[4] = {0, 0, 1, -1};
ll ny[4] = {1, -1, 0, 0};
char a[N][N];
ll dp[N][N];
struct viet{
ll x, y, v;
bool operator <(const viet &o) const{
return v > o.v;
}
};
ll n, m;
bool check(ll x, ll y){
if (x < 1 || x > n || y < 1 || y > m || a[x][y] == '.') return false;
else return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("tests.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> a[i][j];
dp[i][j] = 1e18;
}
}
priority_queue<viet> q;
q.push({1, 1, 1});
dp[1][1] = 1;
ll ans = 1;
while (q.size()){
viet x = q.top();
ans = max(ans, x.v);
q.pop();
for (int i = 0; i < 4; i++){
ll nwx = x.x + nx[i];
ll nwy = x.y + ny[i];
if (!check(nwx, nwy)) continue;
ll cost = x.v + (a[nwx][nwy] != a[x.x][x.y]);
if (dp[nwx][nwy] > cost){
dp[nwx][nwy] = cost;
q.push({nwx, nwy, cost});
}
}
}
cout << ans;
}
/*
Ans:
Out:
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |