Submission #494171

# Submission time Handle Problem Language Result Execution time Memory
494171 2021-12-14T14:28:38 Z MilosMilutinovic Portals (BOI14_portals) C++14
Compilation error
0 ms 0 KB
//todo
#include <bits/stdc++.h>

using namespace std;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int sx, sy, cx, cy;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (s[i][j] == 'C') {
        cx = i;
        cy = j;
      }
    }
  }
  vector<vector<pair<int, int>>> up(n, vector<pair<int, int>>(m));
  vector<vector<pair<int, int>>> down(n, vector<pair<int, int>>(m));
  vector<vector<pair<int, int>>> left(n, vector<pair<int, int>>(m));
  vector<vector<pair<int, int>>> right(n, vector<pair<int, int>>(m));
  //up
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '#') {
        if (i == 0 || up[i - 1][j] == make_pair(-1, -1)) {
          up[i][j] = make_pair(i, j);
        } else {
          up[i][j] = up[i - 1][j];
        }
      } else {
        up[i][j] = make_pair(-1, -1);
      }
    }
  }
  //down
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '#') {
        if (i == n - 1 || down[i + 1][j] == make_pair(-1, -1)) {
          down[i][j] = make_pair(i, j);
        } else {
          down[i][j] = down[i + 1][j];
        }
      } else {
        down[i][j] = make_pair(-1, -1);
      }
    }
  }
  //left
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (s[i][j] != '#') {
        if (j == 0 || left[i][j - 1] == make_pair(-1, -1)) {
          left[i][j] = make_pair(i, j);
        } else {
          left[i][j] = left[i][j - 1];
        }
      } else {
        left[i][j] = make_pair(-1, -1);
      }
    }
  }
  //right
  for (int j = m - 1; j >= 0; j--) {
    for (int i = 0; i < n; i++) {
      if (s[i][j] != '#') {
        if (j == m - 1 || right[i][j + 1] == make_pair(-1, -1)) {
          right[i][j] = make_pair(i, j);
        } else {
          right[i][j] = right[i][j + 1];
        }
      } else {
        right[i][j] = make_pair(-1, -1);
      }
    }
  }
  /*for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << "{" << up[i][j].first << ", " << up[i][j].second << "}" << " ";
    }
    cout << "\n";
  }*/
  vector<vector<vector<pair<int, int>>>> g(n, vector<vector<pair<int, int>>>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') continue;
      if (up[i][j] != make_pair(-1, -1))) {
        g[i][j].push_back(up[i][j]);
      }
      if (down[i][j] != make_pair(-1, -1))) {
        g[i][j].push_back(down[i][j]);
      }
      if (left[i][j] != make_pair(-1, -1))) {
        g[i][j].push_back(left[i][j]);
      }
      if (right[i][j] != make_pair(-1, -1))) {
        g[i][j].push_back(right[i][j]);
      }
      for (int foo = 0; foo < 4; foo++) {
        int ni = i + dx[foo], nj = j + dy[foo];
        if (ni >= 0 && ni < n && nj >= 0 && nj < m && s[ni][nj] != '#') {
          g[i][j].push_back(make_pair(ni, nj));
        }
      }
    }
  }
  deque<pair<int, int>> q = {sx, sy};
  vector<vector<int>> dist(n, vector<int>(m, -1));
  while (!q.empty()) {
  }
  cout << dist[ex][ey];
  return 0;
}

Compilation message

portals.cpp: In function 'int main()':
portals.cpp:101:41: error: expected primary-expression before ')' token
  101 |       if (up[i][j] != make_pair(-1, -1))) {
      |                                         ^
portals.cpp:104:43: error: expected primary-expression before ')' token
  104 |       if (down[i][j] != make_pair(-1, -1))) {
      |                                           ^
portals.cpp:107:43: error: expected primary-expression before ')' token
  107 |       if (left[i][j] != make_pair(-1, -1))) {
      |                                           ^
portals.cpp:110:44: error: expected primary-expression before ')' token
  110 |       if (right[i][j] != make_pair(-1, -1))) {
      |                                            ^
portals.cpp:121:36: error: could not convert '{sx, sy}' from '<brace-enclosed initializer list>' to 'std::deque<std::pair<int, int> >'
  121 |   deque<pair<int, int>> q = {sx, sy};
      |                                    ^
      |                                    |
      |                                    <brace-enclosed initializer list>
portals.cpp:125:16: error: 'ex' was not declared in this scope; did you mean 'cx'?
  125 |   cout << dist[ex][ey];
      |                ^~
      |                cx
portals.cpp:125:20: error: 'ey' was not declared in this scope; did you mean 'cy'?
  125 |   cout << dist[ex][ey];
      |                    ^~
      |                    cy