# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968219 | ShauryaTheShep | Robots (APIO13_robots) | C++17 | Compilation error | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;
const int MAX_W = 10;
const int MAX_H = 10;
char grid[MAX_H][MAX_W];
int w, h;
bool is_inside(int x, int y) {
return x >= 0 && x < h && y >= 0 && y < w;
}
vector<pair<int, int>> get_moves(int x, int y) {
vector<pair<int, int>> positions;
// Directions: Up, Down, Left, Right
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
for (int d = 0; d < 4; ++d) {
int nx = x, ny = y;
while (is_inside(nx + dx[d], ny + dy[d]) && grid[nx + dx[d]][ny + dy[d]] != 'x') {
nx += dx[d];
ny += dy[d];
}
if (nx != x || ny != y) { // Only consider this move if it changes the position
positions.push_back({nx, ny});
}
}
return positions;
}
int bfs(pair<int, int> robot1, pair<int, int> robot2) {
queue<tuple<pair<int, int>, pair<int, int>, int>> q;
set<pair<pair<int, int>, pair<int, int>>> visited;
q.push({robot1, robot2, 0});
visited.insert({robot1, robot2});
while (!q.empty()) {
auto [r1, r2, moves] = q.front(); q.pop();
if (r1 == r2) return moves; // Early termination on merge
auto moves_r1 = get_moves(r1.first, r1.second);
auto moves_r2 = get_moves(r2.first, r2.second);
for (auto& nr1 : moves_r1) {
if (!visited.count({nr1, r2})) {
visited.insert({nr1, r2});
q.push({nr1, r2, moves + 1});
}
}
for (auto& nr2 : moves_r2) {
if (!visited.count({r1, nr2})) {
visited.insert({r1, nr2});
q.push({r1, nr2, moves + 1});
}
}
}
return -1; // If no solution is possible
}
int main() {
cin >> w >> h;
pair<int, int> robot1, robot2;
bool first_robot_found = false;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> grid[i][j];
if (isdigit(grid[i][j])) {
if (!first_robot_found) {
robot1 = {i, j};
first_robot_found = true;
} else {
robot2 = {i, j};
}
}
}
}
cout << bfs(robot1, robot2) << endl;
return 0;
}
Compilation message (stderr)
robots.cpp: In function 'int bfs(std::pair<int, int>, std::pair<int, int>)': robots.cpp:38:31: error: no matching function for call to 'std::queue<std::tuple<std::pair<int, int>, std::pair<int, int>, int> >::push(<brace-enclosed initializer list>)' 38 | q.push({robot1, robot2, 0}); | ^ In file included from /usr/include/c++/10/queue:64, from robots.cpp:3: /usr/include/c++/10/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::tuple<std::pair<int, int>, std::pair<int, int>, int>; _Sequence = std::deque<std::tuple<std::pair<int, int>, std::pair<int, int>, int>, std::allocator<std::tuple<std::pair<int, int>, std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::tuple<std::pair<int, int>, std::pair<int, int>, int>]' 265 | push(const value_type& __x) | ^~~~ /usr/include/c++/10/bits/stl_queue.h:265:30: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::tuple<std::pair<int, int>, std::pair<int, int>, int>&'} 265 | push(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::tuple<std::pair<int, int>, std::pair<int, int>, int>; _Sequence = std::deque<std::tuple<std::pair<int, int>, std::pair<int, int>, int>, std::allocator<std::tuple<std::pair<int, int>, std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::tuple<std::pair<int, int>, std::pair<int, int>, int>]' 270 | push(value_type&& __x) | ^~~~ /usr/include/c++/10/bits/stl_queue.h:270:25: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::tuple<std::pair<int, int>, std::pair<int, int>, int> >::value_type&&' {aka 'std::tuple<std::pair<int, int>, std::pair<int, int>, int>&&'} 270 | push(value_type&& __x) | ~~~~~~~~~~~~~^~~ robots.cpp:42:14: error: 'std::tuple<std::pair<int, int>, std::pair<int, int>, int> <structured bindings>' has incomplete type 42 | auto [r1, r2, moves] = q.front(); q.pop(); | ^~~~~~~~~~~~~~~ robots.cpp:49:41: error: no matching function for call to 'std::set<std::pair<std::pair<int, int>, std::pair<int, int> > >::count(<brace-enclosed initializer list>)' 49 | if (!visited.count({nr1, r2})) { | ^ In file included from /usr/include/c++/10/set:61, from robots.cpp:4: /usr/include/c++/10/bits/stl_set.h:748:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<std::pair<int, int>, std::pair<int, int> >]' 748 | count(const key_type& __x) const | ^~~~~ /usr/include/c++/10/bits/stl_set.h:748:29: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<std::pair<int, int>, std::pair<int, int> >&'} 748 | count(const key_type& __x) const | ~~~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_set.h:754:2: note: candidate: 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = _Kt; _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >]' 754 | count(const _Kt& __x) const | ^~~~~ /usr/include/c++/10/bits/stl_set.h:754:2: note: template argument deduction/substitution failed: robots.cpp:49:41: note: couldn't deduce template parameter '_Kt' 49 | if (!visited.count({nr1, r2})) { | ^ robots.cpp:50:41: error: no matching function for call to 'std::set<std::pair<std::pair<int, int>, std::pair<int, int> > >::insert(<brace-enclosed initializer list>)' 50 | visited.insert({nr1, r2}); | ^ In file included from /usr/include/c++/10/set:61, from robots.cpp:4: /usr/include/c++/10/bits/stl_set.h:509:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<std::pair<int, int>, std::pair<int, int> >]' 509 | insert(const value_type& __x) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:509:32: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<std::pair<int, int>, std::pair<int, int> >&'} 509 | insert(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_set.h:518:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<std::pair<int, int>, std::pair<int, int> >]' 518 | insert(value_type&& __x) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:518:27: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::pair<std::pair<int, int>, std::pair<int, int> > >::value_type&&' {aka 'std::pair<std::pair<int, int>, std::pair<int, int> >&&'} 518 | insert(value_type&& __x) | ~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_set.h:546:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<std::pair<int, int>, std::pair<int, int> >]' 546 | insert(const_iterator __position, const value_type& __x) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:546:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/10/bits/stl_set.h:551:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<std::pair<int, int>, std::pair<int, int> >]' 551 | insert(const_iterator __position, value_type&& __x) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:551:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/10/bits/stl_set.h:566:2: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >]' 566 | insert(_InputIterator __first, _InputIterator __last) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:566:2: note: template argument deduction/substitution failed: robots.cpp:50:41: note: candidate expects 2 arguments, 1 provided 50 | visited.insert({nr1, r2}); | ^ In file included from /usr/include/c++/10/set:61, from robots.cpp:4: /usr/include/c++/10/bits/stl_set.h:578:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >]' 578 | insert(initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:578:43: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::pair<std::pair<int, int>, std::pair<int, int> > >' 578 | insert(initializer_list<value_type> __l) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_set.h:598:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::insert_return_type std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::node_type&&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; std::set<_Key, _Compare, _Alloc>::insert_return_type = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::insert_return_type; std::set<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::node_type]' 598 | insert(node_type&& __nh) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:598:26: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::pair<std::pair<int, int>, std::pair<int, int> > >::node_type&&' {aka 'std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::node_type&&'} 598 | insert(node_type&& __nh) | ~~~~~~~~~~~~^~~~ /usr/include/c++/10/bits/stl_set.h:603:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::node_type&&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::const_iterator; std::set<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int> >, std::pair<std::pair<int, int>, std::pair<int, int> >, std::_Identity<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > > >::node_type]' 603 | insert(const_iterator __hint, node_type&& __nh) | ^~~~~~ /usr/include/c++/10/bits/stl_set.h:603:7: note: candidate expects 2 arguments, 1 provided robots.cpp:51:44: error: no matching function for call to 'std::queue<std::tuple<std::pair<int, int>, std::pair<int, int>, int> >::push(<brace-enclosed initializer list>)' 51 | q.push({nr1, r2, moves + 1}); | ^ In file included from /usr/include/c++/10/queue:64, from robots.cpp:3: /usr/include/c++/10/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::tuple<std::pair<int, int>, std::pair<int, int>, int>; _Sequence = std::deque<std::tuple<std::pair<int, int>, std::pair<int, int>, int>, std::allocator<std::tuple<std::pair<int, int>, std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::tuple<std::pair<int, int>, std::pair<int, int>, int>]' 265 | push(const value_type& __x) | ^~~~ /usr/include/c++/10/bits/stl_queue.h:265:30: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::tuple<std::pair<int, int>, std::pair<int, int>, int>&'} 265 | push(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::tuple<std::pair<int, int>, std::pair<int, int>, int>; _Sequence = std::deque<std::tuple<std::pair<int, int>, std::pair<int, int>, int>, std::allocator<std::tuple<std::pair<int, int>, std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::tuple<std::pair<int, int>, std::pair<int, int>, int>]' 270 | push(value_type&& __x) | ^~~~ /usr/include/c++/10/bits/stl_queue.h:270:25: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::tuple<std::pair<int, int>, std::pair<int, int>, int> >::value_type&&' {aka 'std::tuple<std::pair<int, int>, std::pair<int, int>, int>&&'} 270 | push(value_type&& __x) | ~~~~~~~~~~~~~^~~ robots.cpp:56:41: error: no matching function for call to 'std::set<std::pair<std::pair<int, int>, std::pair<int, int> > >::count(<brace-enclosed initializer list>)' 56 | if (!visited.count({r1, nr2})) { | ^ In file included from /usr/include/c++/10/set:61, from robots.cpp:4: /usr/include/c++/10/bits/stl_set.h:748:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Compare = std::less<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<std::pair<int, int>, std::pair<int, int> >]' 748 | count(const key_type& __x) const | ^~~~~ /usr/include/c++/10/bits/stl_set.h:748:29: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<std::pair<int, int>, std::pair<int, int> >&'} 748 | count(const key_type& __x) const | ~~~~~~~~~~~~~