Submission #1332852

#TimeUsernameProblemLanguageResultExecution timeMemory
1332852HduongTracks in the Snow (BOI13_tracks)C++20
100 / 100
468 ms215372 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)

tracks.cpp: In function 'int main()':
tracks.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen(task".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...