| Task: | Abandoned warehouse |
| Sender: | aalto26bm_048 |
| Submission time: | 2026-09-07 17:01:21 +0300 |
| Language: | C++ (C++23) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.07 s | details |
| #7 | ACCEPTED | 0.12 s | details |
| #8 | ACCEPTED | 0.11 s | details |
| #9 | ACCEPTED | 0.19 s | details |
| #10 | ACCEPTED | 0.20 s | details |
| #11 | ACCEPTED | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.10 s | details |
| #14 | ACCEPTED | 0.00 s | details |
| #15 | ACCEPTED | 0.00 s | details |
| #16 | ACCEPTED | 0.20 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:65:10: warning: unused variable 'done' [-Wunused-variable]
65 | bool done = false;
| ^~~~
input/code.cpp:85:9: warning: 'endx' may be used uninitialized [-Wmaybe-uninitialized]
85 | if (parentx == endx && parenty == endy)
| ^~
input/code.cpp:28:25: note: 'endx' was declared here
28 | int startx, starty, endx, endy;
| ^~~~
input/code.cpp:85:29: warning: 'endy' may be used uninitialized [-Wmaybe-uninitialized]
85 | if (parentx == endx && parenty == endy)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
input/code.cpp:28:31: note: 'endy' was declared here
28 | int startx, starty, endx, endy;
| ^~~~
In file included from /usr/include/c++/13/bits/char_traits.h:57,
from /usr/include/c++/13/ios:42,
from /usr/include/c++/13/ostream:40,
from /usr/...Code
#include <iostream>
#include <vector>
#include <limits>
#include <queue>
#include <set>
#include <utility>
struct Point {
int cost = std::numeric_limits<int>::max();
bool walkable = false;
char parent = '#';
};
int main()
{
int height, width;
std::cin >> height >> width;
std::vector<Point> points(height * width);
// std::mdspan grid(points.data(),width,height);
const auto& grid = [&](int x, int y) -> Point&
{
return points[x + y*width];
};
int startx, starty, endx, endy;
std::set<std::pair<int,int>> visited;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
char c;
std::cin >> c;
if (c == '#')
continue;
auto& point = grid(x,y);
point.walkable = true;
if (c == 'A')
{
startx = x;
starty = y;
point.cost = 0;
} else if (c == 'B')
{
endx = x;
endy = y;
}
}
}
// violates invariants but it should be fine
const auto cmp = [&](const std::pair<int,int>& a, const std::pair<int,int>& b)
{
return grid(a.first,a.second).cost > grid(b.first,b.second).cost;
};
std::priority_queue<std::pair<int,int>, std::vector<std::pair<int,int>>, decltype(cmp)> minheap(cmp);
minheap.push({startx,starty});
bool done = false;
const auto update = [&](int x, int y, int new_cost, char parent_dir)
{
if (!(0 <= x && x < width && 0 <= y && y < height))
return;
auto& point = grid(x,y);
if (point.walkable && new_cost < point.cost)
{
point.cost = new_cost;
point.parent = parent_dir;
minheap.push({x,y});
}
};
bool found_path = false;
while (!minheap.empty())
{
auto [parentx, parenty] = minheap.top();
minheap.pop();
if (parentx == endx && parenty == endy)
{
found_path = true;
break;
}
int new_cost = grid(parentx,parenty).cost + 1;
update(parentx+1,parenty,new_cost,'R');
update(parentx-1,parenty,new_cost,'L');
update(parentx,parenty+1,new_cost,'D');
update(parentx,parenty-1,new_cost,'U');
}
if (!found_path)
{
std::cout << "NO";
return 0;
}
std::vector<char> path;
int currentx = endx;
int currenty = endy;
while (true)
{
auto& point = grid(currentx,currenty);
if (point.parent == '#' || (currentx == startx && currenty == starty))
break;
switch (point.parent)
{
case 'L':
currentx++;
break;
case 'R':
currentx--;
break;
case 'D':
currenty--;
break;
case 'U':
currenty++;
break;
}
path.push_back(point.parent);
}
std::cout << "YES\n" << path.size() << std::endl;
for (auto it = path.rbegin(); it != path.rend(); it++)
{
std::cout << *it;
}
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 10 ##.A###### #.##.##.## #####..### .######### ... |
| correct output |
|---|
| NO |
| user output |
|---|
| NO |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 10 B#..##.#.. #....A##.. #.....#..# .#......#. ... |
| correct output |
|---|
| NO |
| user output |
|---|
| NO |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 10 10 ...#..A.#. ....B...## ...#...... .......... ... |
| correct output |
|---|
| YES 3 LLD |
| user output |
|---|
| YES 3 LLD |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 10 10 .#........ .......... .......... ........#. ... |
| correct output |
|---|
| YES 1 R |
| user output |
|---|
| YES 1 R |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 .......... .......... .......... .......... ... |
| correct output |
|---|
| YES 3 RDD |
| user output |
|---|
| YES 3 RDD |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ##.###..######.#########.###.#... |
| correct output |
|---|
| NO |
| user output |
|---|
| NO |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ####.#.###....#.......##.##.#.... |
| correct output |
|---|
| YES 626 LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL... |
| user output |
|---|
| YES 626 RDDDDLDDDLDLLLDLLDDLDDDDLLLDDL... |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ....#.##......#....#......#...... |
| correct output |
|---|
| YES 364 LULULLULLLULLLLLUULLLLUUULLLLL... |
| user output |
|---|
| YES 364 UUUULULUUUULLLLLUULLUUUUUUUUUL... |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 .................#......#........ |
| correct output |
|---|
| YES 1003 LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL... |
| user output |
|---|
| YES 1003 LLLLLLLLLLLLLLLLLLLLLLLLDLLLLL... |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ................................. |
| correct output |
|---|
| YES 947 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL... |
| user output |
|---|
| YES 947 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL... |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 1000 3 A#B .#. .#. .#. ... |
| correct output |
|---|
| YES 2000 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
| user output |
|---|
| YES 2000 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 3 1000 A................................ |
| correct output |
|---|
| YES 2000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
| user output |
|---|
| YES 2000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 999 999 A#...#...#...#...#...#...#...#... |
| correct output |
|---|
| YES 499998 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
| user output |
|---|
| YES 499998 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 1 3 A.B |
| correct output |
|---|
| YES 2 RR |
| user output |
|---|
| YES 2 RR |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 2 2 ## AB |
| correct output |
|---|
| YES 1 R |
| user output |
|---|
| YES 1 R |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 A................................ |
| correct output |
|---|
| YES 1998 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
| user output |
|---|
| YES 1998 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
