Submission #389902

#TimeUsernameProblemLanguageResultExecution timeMemory
389902null_aweTracks in the Snow (BOI13_tracks)C++14
31.25 / 100
2146 ms811040 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> field(h, vector<int>(w, 0)), filled(h, vector<int>(w, 0));
  for (int i = 0; i < h; ++i) {
    string line;
    cin >> line;
    for (int j = 0; j < w; ++j) field[i][j] = (line[j] == '.' ? -1 : (line[j] == 'R' ? 1 : 2));
  }
  int r = 0;
  vector<vector<int>> next;
  vector<int> first{0, 0};
  next.push_back(first);
  while (!next.empty()) {
    queue<vector<int>> q;
    for (vector<int> go : next) q.push(go);
    next.clear();
    while (!q.empty()) {
      vector<int> square = q.front();
      q.pop();
      for (int i = 0; i < 4; ++i) {
        int newX = square[0] + dx[i], newY = square[1] + dy[i];
        if (newX < 0 || newY < 0 || newX >= h || newY >= w) continue;
        if (filled[newX][newY] > 0 || field[newX][newY] < 0) continue;
        vector<int> add{newX, newY};
        if (field[newX][newY] == field[square[0]][square[1]]) q.push(add);
        else next.push_back(add);
      }
      filled[square[0]][square[1]] = 1;
    }
    r++;
  }
  cout << r;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...