제출 #1329444

#제출 시각아이디문제언어결과실행 시간메모리
1329444adrianaTravelling Trader (CCO23_day2problem2)C++20
컴파일 에러
0 ms0 KiB
class Solution {
 public:
  int minimumCost(vector<int>& start, vector<int>& target,
                  vector<vector<int>>& specialRoads) {
    return dijkstra(specialRoads, start[0], start[1], target[0], target[1]);
  }

 private:
  int dijkstra(const vector<vector<int>>& specialRoads, int srcX, int srcY,
               int dstX, int dstY) {
    const int n = specialRoads.size();
    // dist[i] := the minimum distance of (srcX, srcY) to
    // specialRoads[i](x2, y2)
    vector<int> dist(specialRoads.size(), INT_MAX);
    using P = pair<int, int>;  // (d, u), where u := the i-th specialRoads
    priority_queue<P, vector<P>, greater<>> minHeap;

    // (srcX, srcY) -> (x1, y1) to cost -> (x2, y2)
    for (int u = 0; u < n; ++u) {
      const int x1 = specialRoads[u][0];
      const int y1 = specialRoads[u][1];
      const int cost = specialRoads[u][4];
      const int d = abs(x1 - srcX) + abs(y1 - srcY) + cost;
      dist[u] = d;
      minHeap.emplace(dist[u], u);
    }

    while (!minHeap.empty()) {
      const auto [d, u] = minHeap.top();
      minHeap.pop();
      if (d > dist[u])
        continue;
      const int ux2 = specialRoads[u][2];
      const int uy2 = specialRoads[u][3];
      for (int v = 0; v < n; ++v) {
        if (v == u)
          continue;
        const int vx1 = specialRoads[v][0];
        const int vy1 = specialRoads[v][1];
        const int vcost = specialRoads[v][4];
        // (ux2, uy2) -> (vx1, vy1) to vcost -> (vx2, vy2)
        const int newDist = d + abs(vx1 - ux2) + abs(vy1 - uy2) + vcost;
        if (newDist < dist[v]) {
          dist[v] = newDist;
          minHeap.emplace(dist[v], v);
        }
      }
    }

    int ans = abs(dstX - srcX) + abs(dstY - srcY);
    for (int u = 0; u < n; ++u) {
      const int x2 = specialRoads[u][2];
      const int y2 = specialRoads[u][3];
      // (srcX, srcY) -> (x2, y2) -> (dstX, dstY).
      ans = min(ans, dist[u] + abs(dstX - x2) + abs(dstY - y2));
    }
    return ans;
  }
};

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:3:19: error: 'vector' has not been declared
    3 |   int minimumCost(vector<int>& start, vector<int>& target,
      |                   ^~~~~~
Main.cpp:3:25: error: expected ',' or '...' before '<' token
    3 |   int minimumCost(vector<int>& start, vector<int>& target,
      |                         ^
Main.cpp:9:29: error: 'vector' was not declared in this scope
    9 |   int dijkstra(const vector<vector<int>>& specialRoads, int srcX, int srcY,
      |                             ^~~~~~
Main.cpp:9:29: error: 'vector' was not declared in this scope
Main.cpp:9:29: error: 'vector' was not declared in this scope
Main.cpp:9:29: error: 'vector' was not declared in this scope
Main.cpp:9:29: error: 'vector' was not declared in this scope
Main.cpp:9:29: error: 'vector' was not declared in this scope
Main.cpp:9:22: error: 'vector' does not name a type
    9 |   int dijkstra(const vector<vector<int>>& specialRoads, int srcX, int srcY,
      |                      ^~~~~~
Main.cpp:9:28: error: expected ',' or '...' before '<' token
    9 |   int dijkstra(const vector<vector<int>>& specialRoads, int srcX, int srcY,
      |                            ^
Main.cpp: In member function 'int Solution::minimumCost(int)':
Main.cpp:5:21: error: 'specialRoads' was not declared in this scope
    5 |     return dijkstra(specialRoads, start[0], start[1], target[0], target[1]);
      |                     ^~~~~~~~~~~~
Main.cpp:5:35: error: 'start' was not declared in this scope
    5 |     return dijkstra(specialRoads, start[0], start[1], target[0], target[1]);
      |                                   ^~~~~
Main.cpp:5:55: error: 'target' was not declared in this scope
    5 |     return dijkstra(specialRoads, start[0], start[1], target[0], target[1]);
      |                                                       ^~~~~~
Main.cpp: In member function 'int Solution::dijkstra(int)':
Main.cpp:11:19: error: 'specialRoads' was not declared in this scope
   11 |     const int n = specialRoads.size();
      |                   ^~~~~~~~~~~~
Main.cpp:14:5: error: 'vector' was not declared in this scope
   14 |     vector<int> dist(specialRoads.size(), INT_MAX);
      |     ^~~~~~
Main.cpp:14:12: error: expected primary-expression before 'int'
   14 |     vector<int> dist(specialRoads.size(), INT_MAX);
      |            ^~~
Main.cpp:15:15: error: 'pair' does not name a type
   15 |     using P = pair<int, int>;  // (d, u), where u := the i-th specialRoads
      |               ^~~~
Main.cpp:16:20: error: 'P' was not declared in this scope
   16 |     priority_queue<P, vector<P>, greater<>> minHeap;
      |                    ^
Main.cpp:16:5: error: 'priority_queue' was not declared in this scope
   16 |     priority_queue<P, vector<P>, greater<>> minHeap;
      |     ^~~~~~~~~~~~~~
Main.cpp:16:32: error: expected primary-expression before ',' token
   16 |     priority_queue<P, vector<P>, greater<>> minHeap;
      |                                ^
Main.cpp:16:34: error: 'greater' was not declared in this scope
   16 |     priority_queue<P, vector<P>, greater<>> minHeap;
      |                                  ^~~~~~~
Main.cpp:16:42: error: expected primary-expression before '>' token
   16 |     priority_queue<P, vector<P>, greater<>> minHeap;
      |                                          ^~
Main.cpp:16:45: error: 'minHeap' was not declared in this scope
   16 |     priority_queue<P, vector<P>, greater<>> minHeap;
      |                                             ^~~~~~~
Main.cpp:23:30: error: 'srcX' was not declared in this scope
   23 |       const int d = abs(x1 - srcX) + abs(y1 - srcY) + cost;
      |                              ^~~~
Main.cpp:23:21: error: 'abs' was not declared in this scope
   23 |       const int d = abs(x1 - srcX) + abs(y1 - srcY) + cost;
      |                     ^~~
Main.cpp:23:47: error: 'srcY' was not declared in this scope
   23 |       const int d = abs(x1 - srcX) + abs(y1 - srcY) + cost;
      |                                               ^~~~
Main.cpp:24:7: error: 'dist' was not declared in this scope
   24 |       dist[u] = d;
      |       ^~~~
Main.cpp:31:15: error: 'dist' was not declared in this scope
   31 |       if (d > dist[u])
      |               ^~~~
Main.cpp:42:33: error: 'abs' was not declared in this scope
   42 |         const int newDist = d + abs(vx1 - ux2) + abs(vy1 - uy2) + vcost;
      |                                 ^~~
Main.cpp:43:23: error: 'dist' was not declared in this scope
   43 |         if (newDist < dist[v]) {
      |                       ^~~~
Main.cpp:50:19: error: 'dstX' was not declared in this scope
   50 |     int ans = abs(dstX - srcX) + abs(dstY - srcY);
      |                   ^~~~
Main.cpp:50:26: error: 'srcX' was not declared in this scope
   50 |     int ans = abs(dstX - srcX) + abs(dstY - srcY);
      |                          ^~~~
Main.cpp:50:15: error: 'abs' was not declared in this scope; did you mean 'ans'?
   50 |     int ans = abs(dstX - srcX) + abs(dstY - srcY);
      |               ^~~
      |               ans
Main.cpp:50:38: error: 'dstY' was not declared in this scope
   50 |     int ans = abs(dstX - srcX) + abs(dstY - srcY);
      |                                      ^~~~
Main.cpp:50:45: error: 'srcY' was not declared in this scope
   50 |     int ans = abs(dstX - srcX) + abs(dstY - srcY);
      |                                             ^~~~
Main.cpp:55:22: error: 'dist' was not declared in this scope
   55 |       ans = min(ans, dist[u] + abs(dstX - x2) + abs(dstY - y2));
      |                      ^~~~
Main.cpp:55:13: error: 'min' was not declared in this scope
   55 |       ans = min(ans, dist[u] + abs(dstX - x2) + abs(dstY - y2));
      |             ^~~