# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445066 | KazamaHoang | Tracks in the Snow (BOI13_tracks) | C++14 | 25 ms | 1740 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>
#define F first
#define S second
#define eb emplace_back
#define bit(x, i) (((x) >> (i)) & 1)
#define sz(x) ((int)x.size())
using namespace std;
using ll = long long;
const int inf = 1061109567;
const ll INF = 4557430888798830399;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
int numRow, numCol;
char snow[405][405];
int dist[405][405];
bool outSide(int ux, int vy) {
if (ux == 0 || ux == numRow || vy == 0 || vy == numCol || snow[ux][vy] == '.' || dist[ux][vy] != -1)
return true;
return false;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
#define Task ""
if (fopen(Task".in", "r")) {
freopen(Task".in", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> numRow >> numCol;
for (int i = 1; i <= numRow; ++ i)
for (int j = 1; j <= numCol; ++ j)
cin >> snow[i][j];
memset(dist, -1, sizeof(dist));
deque <pair <int, int>> dq;
dq.push_back({1, 1});
dist[1][1] = 0;
while (!dq.empty()) {
int u = dq.front().F;
int v = dq.front().S;
dq.pop_front();
for (int i = 0; i <= 3; ++ i) {
int ux = u + dx[i];
int vy = v + dy[i];
if (outSide(ux, vy))
continue;
if (snow[ux][vy] == snow[u][v]) {
dq.push_front({ux, vy});
dist[ux][vy] = dist[u][v];
} else {
dq.push_back({ux, vy});
dist[ux][vy] = dist[u][v] + 1;
}
}
}
int res = 0;
for (int i = 1; i <= numRow; ++ i)
for (int j = 1; j <= numCol; ++ j)
res = max(res, dist[i][j]);
cout << res + 1;
return 0;
}
// Written by Kazama Hoang ^^
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |