| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1332852 | Hduong | Tracks in the Snow (BOI13_tracks) | C++20 | 468 ms | 215372 KiB |
#include <bits/stdc++.h>
#define task "task"
using namespace std;
const int N = 42e2 + 2;
long long h, w;
char a[N][N];
long long dx[4] = {1, -1, 0, 0},
dy[4] = {0, 0, 1, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> h >> w;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
cin >> a[i][j];
deque <pair<long long , long long>> q;
q.push_back({1,1});
char last = 'R' + 'F' - a[1][1];
long long res = 0;
while (!q.empty()) {
auto u = q.front();
q.pop_front();
long long x = u.first, y = u.second;
char cur = a[x][y];
if (cur == 0) continue;
a[x][y] = 0;
if (cur != last) {
last = cur;
res++;
}
for (int k = 0; k < 4; k++) {
long long nx = x + dx[k], ny = y + dy[k];
char nxt = a[nx][ny];
if (nxt == cur)
q.push_front({nx, ny});
else if (nxt + cur == 'R' + 'F')
q.push_back({nx, ny});
}
}
cout << res;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
