제출 #1120072

#제출 시각아이디문제언어결과실행 시간메모리
1120072dowdowBitaro’s Party (JOI18_bitaro)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include <vector> #include <set> #include <stack> #include <climits> using namespace std; class Graph { public: int V; // Number of vertices vector<vector< pair<uint, uint>>> adj; // adjacency list (pair of vertex and weight) Graph(int V) { this->V = V; adj.resize(V+1); // Vertex starts from 1 to V, skip index 0 } // Add an edge from u to v with weight w void addEdge(int u, int v, int w) { adj[u].push_back({v, w}); } // Helper function for topological sort using DFS void topologicalSortUtil(int v, vector<bool>& visited, stack<int>& topoStack) { visited[v] = true; // Recur for all the vertices adjacent to this vertex for (auto& neighbor : adj[v]) { int u = neighbor.first; if (!visited[u]) { topologicalSortUtil(u, visited, topoStack); } } // Push current vertex to stack after visiting all its neighbors topoStack.push(v); } // Function to perform topological sort stack<int> topologicalSort() { vector<bool> visited(V, false); stack<int> topoStack; // Perform DFS for all unvisited vertices for (int i = 0; i < V; i++) { if (!visited[i]) { topologicalSortUtil(i, visited, topoStack); } } return topoStack; } // Function to find the longest path in the DAG int longestPath(int src, const set<uint>& unattended) { // stack<int> topoStack = topologicalSort(); // cout << src << endl; // Initialize distances to all vertices as negative infinity vector<int> dist(V, INT_MIN); dist[src] = 0; // Distance to the source is 0 // Process vertices in topological order from src and above //while (!topoStack.empty()) { // int u = topoStack.top(); // topoStack.pop(); for (int i = src; i > 0; i--) { int u = i; // cout << u << endl; // Update distances for all adjacent vertices of u if (dist[u] != INT_MIN) { for (auto& neighbor : adj[u]) { int v = neighbor.first; int weight = neighbor.second; if (neighbor.first > src) { continue; } // cout << "Neighbor" << v << " weight: " << weight<< endl; if (dist[u] + weight > dist[v]) { dist[v] = dist[u] + weight; // cout << "distance[v]: " << dist[v] << endl; } } } } // Find the longest path int max_dist = -1; for (int i = 1; i <= src; i++) { // cout << i << endl; // cout << "unattended size: " << unattended.size() << endl; if (unattended.find(i) != unattended.end()) { // cout << "unattended: " << i << endl; continue; } if (dist[i] > max_dist) { max_dist = dist[i]; } } // cout << "max_dist: " << max_dist << endl; return max_dist; } }; class Gathering { public: uint Town; uint number; // # of beavers couldn't come set<uint> beavers; // beavers couldn't come int max_path; // longest canal for beavers could come Gathering(uint T, uint number) { this->Town = T; this->number = number; this->max_path = -1; } Gathering(const Gathering& G) { this->Town = G.Town; this->number = G.number; this->max_path = G.max_path; this->beavers = G.beavers; // cout << " copy constructor: " << this->beavers.size() << " input: " << G.beavers.size() << endl; } void addBeaver(uint beaver) { beavers.insert(beaver); } }; class Node { public: int value; vector<pair<int, int>> *multi; Node(int value) { this->value = value; } vector<pair<int, int>>* pairs() { return multi; } }; class Matrix { private: int rows; int cols; std::vector<std::vector<Node*>> data; // std::vector<std::pair<int, int>> multi; // a set of multiples public: // Constructor to initialize a matrix with given rows and columns, and optionally fill with a value Matrix(int r, int c) : rows(r), cols(c) {} // Copy constructor to create a deep copy of another matrix Matrix(const Matrix& other) : rows(other.rows), cols(other.cols), data(other.data) {} // Accessor for rows and columns int getRows() const { return rows; } int getCols() const { return cols; } // Element access (with bounds checking) Node *at(int r, int c) { if (r < 0 || r >= rows || c < 0 || c >= cols) { throw std::out_of_range("Index out of bounds"); } return data[r][c]; } // Set data void set_at(int r, int c, Node* node) { if (r < 0 || r >= rows || c < 0 || c >= cols) { throw std::out_of_range("Index out of bounds"); } data[r][c] = node; } // Display the matrix void display() const { for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { std::cout << data[i][j]->value << " "; } std::cout << std::endl; } } }; int main() { uint R = 0; uint S = 0; uint N = 0; cin >> R >> S >> N; // Add edges: (from, to, weight) Matrix matrix(R,S); // Create a matrix with R*S for(int i = 0; i < R; i++) { for(int j = 0; j < S; j++) { uint value = 0; cin >> value; Node *node = new Node(value); matrix.set_at(i, j, node); } } for(int i = S; i > 0; i--) { for(int j = R; j > 0; j--) { Node *node = matrix.at(i,j); if (i < S) { Node *right_node = matrix.at(i+1, j); for (auto& multi: right_node->pairs()) { node->multi.push_back(right_node->pairs()); node->multi.push_back({i+1, right_node->value}); } } if (j < R) { Node *down_node = matrix.at(i,j+1); } for (int k = 0; node->multi.size(); k++) { } } } return 0; }

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

bitaro.cpp: In member function 'int Graph::longestPath(int, const std::set<unsigned int>&)':
bitaro.cpp:75:40: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   75 |                     if (neighbor.first > src) {
      |                         ~~~~~~~~~~~~~~~^~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:201:20: warning: comparison of integer expressions of different signedness: 'int' and 'uint' {aka 'unsigned int'} [-Wsign-compare]
  201 |   for(int i = 0; i < R; i++) {
      |                  ~~^~~
bitaro.cpp:202:22: warning: comparison of integer expressions of different signedness: 'int' and 'uint' {aka 'unsigned int'} [-Wsign-compare]
  202 |     for(int j = 0; j < S; j++) {
      |                    ~~^~~
bitaro.cpp:213:15: warning: comparison of integer expressions of different signedness: 'int' and 'uint' {aka 'unsigned int'} [-Wsign-compare]
  213 |         if (i < S) {
      |             ~~^~~
bitaro.cpp:215:49: error: no matching function for call to 'begin(std::vector<std::pair<int, int> >*&)'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bitaro.cpp:1:
/usr/include/c++/10/initializer_list:90:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)'
   90 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
/usr/include/c++/10/initializer_list:90:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types 'std::initializer_list<_Tp>' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bitaro.cpp:1:
/usr/include/c++/10/bits/range_access.h:51:5: note: candidate: 'template<class _Container> decltype (__cont.begin()) std::begin(_Container&)'
   51 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:51:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container = std::vector<std::pair<int, int> >*]':
bitaro.cpp:215:49:   required from here
/usr/include/c++/10/bits/range_access.h:51:50: error: request for member 'begin' in '__cont', which is of pointer type 'std::vector<std::pair<int, int> >*' (maybe you meant to use '->' ?)
   51 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |                                           ~~~~~~~^~~~~
/usr/include/c++/10/bits/range_access.h:61:5: note: candidate: 'template<class _Container> decltype (__cont.begin()) std::begin(const _Container&)'
   61 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:61:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.begin()) std::begin(const _Container&) [with _Container = std::vector<std::pair<int, int> >*]':
bitaro.cpp:215:49:   required from here
/usr/include/c++/10/bits/range_access.h:61:56: error: request for member 'begin' in '__cont', which is of pointer type 'std::vector<std::pair<int, int> >* const' (maybe you meant to use '->' ?)
   61 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |                                                 ~~~~~~~^~~~~
/usr/include/c++/10/bits/range_access.h:90:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   90 |     begin(_Tp (&__arr)[_Nm])
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:90:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types '_Tp [_Nm]' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from bitaro.cpp:1:
/usr/include/c++/10/valarray:1214:5: note: candidate: 'template<class _Tp> _Tp* std::begin(std::valarray<_Tp>&)'
 1214 |     begin(valarray<_Tp>& __va)
      |     ^~~~~
/usr/include/c++/10/valarray:1214:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types 'std::valarray<_Tp>' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from bitaro.cpp:1:
/usr/include/c++/10/valarray:1224:5: note: candidate: 'template<class _Tp> const _Tp* std::begin(const std::valarray<_Tp>&)'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
/usr/include/c++/10/valarray:1224:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types 'const std::valarray<_Tp>' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
bitaro.cpp:215:49: error: no matching function for call to 'end(std::vector<std::pair<int, int> >*&)'
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bitaro.cpp:1:
/usr/include/c++/10/initializer_list:101:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)'
  101 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
/usr/include/c++/10/initializer_list:101:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types 'std::initializer_list<_Tp>' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bitaro.cpp:1:
/usr/include/c++/10/bits/range_access.h:71:5: note: candidate: 'template<class _Container> decltype (__cont.end()) std::end(_Container&)'
   71 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/10/bits/range_access.h:71:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.end()) std::end(_Container&) [with _Container = std::vector<std::pair<int, int> >*]':
bitaro.cpp:215:49:   required from here
/usr/include/c++/10/bits/range_access.h:71:48: error: request for member 'end' in '__cont', which is of pointer type 'std::vector<std::pair<int, int> >*' (maybe you meant to use '->' ?)
   71 |     end(_Container& __cont) -> decltype(__cont.end())
      |                                         ~~~~~~~^~~
/usr/include/c++/10/bits/range_access.h:81:5: note: candidate: 'template<class _Container> decltype (__cont.end()) std::end(const _Container&)'
   81 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/10/bits/range_access.h:81:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.end()) std::end(const _Container&) [with _Container = std::vector<std::pair<int, int> >*]':
bitaro.cpp:215:49:   required from here
/usr/include/c++/10/bits/range_access.h:81:54: error: request for member 'end' in '__cont', which is of pointer type 'std::vector<std::pair<int, int> >* const' (maybe you meant to use '->' ?)
   81 |     end(const _Container& __cont) -> decltype(__cont.end())
      |                                               ~~~~~~~^~~
/usr/include/c++/10/bits/range_access.h:100:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  100 |     end(_Tp (&__arr)[_Nm])
      |     ^~~
/usr/include/c++/10/bits/range_access.h:100:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types '_Tp [_Nm]' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from bitaro.cpp:1:
/usr/include/c++/10/valarray:1234:5: note: candidate: 'template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)'
 1234 |     end(valarray<_Tp>& __va)
      |     ^~~
/usr/include/c++/10/valarray:1234:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types 'std::valarray<_Tp>' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from bitaro.cpp:1:
/usr/include/c++/10/valarray:1244:5: note: candidate: 'template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
/usr/include/c++/10/valarray:1244:5: note:   template argument deduction/substitution failed:
bitaro.cpp:215:49: note:   mismatched types 'const std::valarray<_Tp>' and 'std::vector<std::pair<int, int> >*'
  215 |             for (auto& multi: right_node->pairs()) {
      |                                                 ^
bitaro.cpp:216:29: error: request for member 'push_back' in 'node->Node::multi', which is of pointer type 'std::vector<std::pair<int, int> >*' (maybe you meant to use '->' ?)
  216 |                 node->multi.push_back(right_node->pairs());
      |                             ^~~~~~~~~
bitaro.cpp:217:29: error: request for member 'push_back' in 'node->Node::multi', which is of pointer type 'std::vector<std::pair<int, int> >*' (maybe you meant to use '->' ?)
  217 |                 node->multi.push_back({i+1, right_node->value});
      |                             ^~~~~~~~~
bitaro.cpp:220:15: warning: comparison of integer expressions of different signedness: 'int' and 'uint' {aka 'unsigned int'} [-Wsign-compare]
  220 |         if (j < R) {
      |             ~~^~~
bitaro.cpp:221:19: warning: unused variable 'down_node' [-Wunused-variable]
  221 |             Node *down_node = matrix.at(i,j+1);
      |                   ^~~~~~~~~
bitaro.cpp:223:37: error: request for member 'size' in 'node->Node::multi', which is of pointer type 'std::vector<std::pair<int, int> >*' (maybe you meant to use '->' ?)
  223 |         for (int k = 0; node->multi.size(); k++) {
      |                                     ^~~~