| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 850457 | thisistotallymyusername | Tracks in the Snow (BOI13_tracks) | C++14 | 412 ms | 128700 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 <iostream>
#include <cstring>
#include <algorithm>
#include <deque>
using namespace std;
typedef pair<int, int> PII;
#define F first
#define S second
const int N = 4010;
char g[N][N];
int n, m, res, d[N][N], dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void bfs() {
deque<PII> q; q.emplace_back(0, 0);
memset(d, 0x3f, sizeof d); d[0][0] = 1;
while (!q.empty()) {
PII t = q.front(); q.pop_front();
res = max(res, d[t.F][t.S]);
for (int i = 0; i < 4; i++) {
int x = t.F + dx[i], y = t.S + dy[i];
if (0 <= x && x < n && 0 <= y && y < m && g[x][y] != '.') {
int w = (g[x][y] != g[t.F][t.S]);
if (d[x][y] > d[t.F][t.S] + w) {
d[x][y] = d[t.F][t.S] + w;
if (w) {
q.emplace_back(x, y);
} else {
q.emplace_front(x, y);
}
}
}
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", g[i]);
bfs();
printf("%d\n", res);
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
