# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67039 | RezwanArefin01 | Tracks in the Snow (BOI13_tracks) | C++17 | 958 ms | 297244 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.
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 4010;
char g[N][N];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int d[N][N], n, m;
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++)
scanf(" %s", g[i]);
deque<ii> q;
memset(d, 63, sizeof d);
q.push_back({0, 0});
d[0][0] = 1 ;
while(!q.empty()) {
ii u = q.front(); q.pop_front();
int x = u.first, y = u.second;
for(int i = 0; i < 4; i++) {
int xx = x + dx[i], yy = y + dy[i];
if(xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] != '.') {
int c = g[x][y] != g[xx][yy];
if(d[xx][yy] > d[x][y] + c) {
d[xx][yy] = d[x][y] + c;
if(c) q.push_back({xx, yy});
else q.push_front({xx, yy});
}
}
}
}
int mx = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) if(g[i][j] != '.') {
mx = max(mx, d[i][j]);
}
}
printf("%d\n", mx);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |