[Community Puzzle] Cylinders

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @java_coffee_cup,validated by @haiko256,@Malte42 and @presidentaz.
If you have any issues, feel free to ping them.

Great puzzle! I loved the combination of the geometry and the optimization. Very hard for me and oh, so satisfying when I finally finished!

1 Like

I am confused a bit - whether I should reorder cylinders (in box) or should I simply calculate the width strictly in given order of cylinders…

You have to reorder them to the minimum width.

I’m wondering if there is a O(N) solution without exploring all permutations…

I do not know a O(N) solution but I know some combinations can be skipped without a full test.

Public TEST case 1

Standard Output Stream:



My solution gave such order

3 542 93 150 135 380 10

My solution gave such order
3 542 93 150 135 380 10

It is best to prove the correctness by yourself.
If you cut out the circles in paper with radii in a correct ratio and arrange them on a line, you can confirm whether the total length can be a ratio of 1639 or should be much more.

Hi, I don’t understand how circles with radius of 3, 2, 2 and 1 can give a minimal width of 9.657.
I found 15.191
I think I’m misounderstood an information but I don’t know which.

Are you reading the statement correctly?

A line starts with integer m, for the number of cylinders, followed by m integers, for the radius of each cylinder.

I have no idea about how should I solve this one, so I asked bing AI, and the result was…

you can measure it using a ruler or another measuring tool. Is there anything else I can help with? :blush:


Time limit is very strict.

I had to replace all vectors with arrays and even precompute a table of sqrts to be able to pass. Unless my solution is of wrong complexity, I would have liked a problem with a less strict time limit.

Some combinations can be skipped, not needing a complete loop through. It may save about 1/3 or 1/4 of running time.

Without using this skipping strategy, my code in java can loop through all combinations within time limit.

Perhaps java nowadays is surpassing some other mainstream languages in efficiency to the extend that I am not aware of.