|
| 1 | +---toml |
| 2 | +[fuzz] |
| 3 | +exec = ["cargo", "run", "--release", "--", "generate"] |
| 4 | +env = {} |
| 5 | + |
| 6 | +[judge] |
| 7 | +exec = ["cargo", "run", "--release", "--quiet", "--", "validate"] |
| 8 | + |
| 9 | +[problem] |
| 10 | +points = 15 |
| 11 | +difficulty = 2 |
| 12 | +--- |
| 13 | + |
| 14 | +# 🧭 Manhattan Courier |
| 15 | + |
| 16 | +As you open your eyes in the morning, |
| 17 | +you grumble as you throw your alarm clock on the ground, |
| 18 | +lamenting the hard day of work ahead at your day job. |
| 19 | +That job, of course, is being a courier in the busy city of Manhattan. |
| 20 | + |
| 21 | +While of course this job is simple enough for some, for you it gets even worse. |
| 22 | +You're not just any old courier, you're a courier in a multiverse! |
| 23 | +That's right, every day, your boss dispatches you to the city of Manhattan |
| 24 | +in some particular multiverse, which means that at the start of every day, |
| 25 | +you get a different map over which you will have to navigate. |
| 26 | + |
| 27 | +There is something peculiar about these alternate reality Manhattans that you have learnt, though. |
| 28 | +1. These buildings are scattered throughout a three-dimensional space, |
| 29 | + meaning a good amount of them are straight up floating. |
| 30 | +2. All modes of transportation to and from different buildings are incapable of travelling |
| 31 | + diagonally, meaning that the cost of moving from one city to another can never be less |
| 32 | + than the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) |
| 33 | + (i.e., sum of absolute differences of coordinates) between their locations. |
| 34 | + For example, the Manhattan distance between `(1, 2, 3)` and `(6, 5, 4)` |
| 35 | + is `|1-6| + |2-5| + |3-4| = 5 + 3 + 1 = 9`. |
| 36 | + |
| 37 | +Of course, being the Employee of the Year two years in a row, |
| 38 | +you're known for being efficient and always finding the shortest path |
| 39 | +to get from one place to another. |
| 40 | +As you get ready for work, a colleague of yours poses you a challenge. |
| 41 | +In addition to a new Manhattan map, they give you the names of two buildings in the map. |
| 42 | +You are asked to find the |
| 43 | +**cost of the shortest path from the first given building to the second one**. |
| 44 | + |
| 45 | +In this case, the "shortest path" refers to the path that incurs the least total cost. |
| 46 | +A cost is incurred every single time you move from one building to another. |
| 47 | + |
| 48 | +## Example |
| 49 | + |
| 50 | +Consider the following input prompt. |
| 51 | +``` |
| 52 | +aaa eee |
| 53 | +aaa(0, 0, 0): bbb(4), ccc(5) |
| 54 | +bbb(0, 1, 1): aaa(3), ccc(2), eee(10) |
| 55 | +ccc(0, 2, 2): ddd(3) |
| 56 | +ddd(1, 3, 1): bbb(4), eee(5) |
| 57 | +eee(2, 4, 3): ccc(8) |
| 58 | +``` |
| 59 | +All paths in the city are *directed*. |
| 60 | +That is, from the above, moving from building `aaa` to `bbb` has a cost of 4, |
| 61 | +while from building `bbb` to `aaa` has a cost of 3. |
| 62 | +Also, in the above, your colleague has challenged you to finding the cost of |
| 63 | +the shortest path from building `aaa` to `eee`, |
| 64 | +which happens to be **13** |
| 65 | +(to `ccc` with cost 5, then to `ddd` with cost 3, then finally to `eee` with cost 5). |
| 66 | + |
| 67 | +## Input |
| 68 | + |
| 69 | +Your input will consist of a series of lines as per the example above. |
| 70 | +The first line contains two space-separated names: |
| 71 | +the first being the building you start at, and the second being the building you end at. |
| 72 | + |
| 73 | +The rest of the lines are in the format of: |
| 74 | +``` |
| 75 | +<building name>(<location coordinates>): [<building name>(<cost>)] ... |
| 76 | +``` |
| 77 | + |
| 78 | +For example, in the above, `aaa(0, 0, 0): bbb(4), ccc(5)` means that |
| 79 | +from building `aaa`, which is located at point `(0, 0, 0)`, |
| 80 | +moving to building `bbb` will incur a cost of 4, |
| 81 | +and moving to building `ccc` will incur a cost of 5. |
| 82 | + |
| 83 | +## Output |
| 84 | + |
| 85 | +Your output will be a single integer, representing the cost of the shortest path |
| 86 | +from the given start building to the given end building. |
| 87 | + |
| 88 | +In the above example, it will be a single integer as follows. |
| 89 | +``` |
| 90 | +13 |
| 91 | +``` |
0 commit comments