SpiralRoute
SRM 371 · 2007-10-13 · by bmerry
Problem Statement
The King of Elbonia lives in a palace that is width meters by length meters. Since he makes his subjects live in mud, he is not very popular. He wants the palace partitioned so that visitors have to walk a long way to reach him. His security advisors have settled on a spiral. A visitor enters the palace at the South-West corner and starts walking East. Every time the visitor reaches an outer wall or his own path, he turns left. The corridors in the spiral are 1 meter wide. The diagram below shows an example of a spiral path: the visitor moves from a (the South-West corner) through the alphabet to x, the throne.
nmlkji oxwvuh pqrstg abcdef
The King wants to have his throne correctly placed before all the partitioning is done, so he needs to know where the spiral will end. Write a class SpiralRoute with a method thronePosition that returns two integers, indicating the coordinates of the throne. The South-West corner is (0, 0), the South-East corner is (width - 1, 0) and the North-East corner is (width - 1, length - 1).
Constraints
- width and length will both be between 1 and 5000, inclusive.
6
4
Returns: {1, 2 }
This is the example above.
6
5
Returns: {3, 2 }
1
11
Returns: {0, 10 }
12
50
Returns: {5, 6 }
50
50
Returns: {24, 25 }
Submissions are judged against all 81 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SpiralRoute with a public method vector<int> thronePosition(int width, int length) · 81 test cases · 2 s / 256 MB per case