Statistics

Problem Statement for "SpiralRoute"

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).

Definition

Class:
SpiralRoute
Method:
thronePosition
Parameters:
int, int
Returns:
int[]
Method signature:
int[] thronePosition(int width, int length)
(be sure your method is public)

Constraints

  • width and length will both be between 1 and 5000, inclusive.

Examples

  1. 6

    4

    Returns: {1, 2 }

    This is the example above.

  2. 6

    5

    Returns: {3, 2 }

  3. 1

    11

    Returns: {0, 10 }

  4. 12

    50

    Returns: {5, 6 }

  5. 50

    50

    Returns: {24, 25 }

  6. 1

    1

    Returns: {0, 0 }

  7. 1

    2

    Returns: {0, 1 }

  8. 1

    3

    Returns: {0, 2 }

  9. 1

    4

    Returns: {0, 3 }

  10. 4

    1

    Returns: {3, 0 }

  11. 3

    1

    Returns: {2, 0 }

  12. 2

    1

    Returns: {1, 0 }

  13. 1

    1

    Returns: {0, 0 }

  14. 2

    2

    Returns: {0, 1 }

  15. 3

    3

    Returns: {1, 1 }

  16. 4

    4

    Returns: {1, 2 }

  17. 5

    5

    Returns: {2, 2 }

  18. 48

    48

    Returns: {23, 24 }

  19. 49

    49

    Returns: {24, 24 }

  20. 50

    50

    Returns: {24, 25 }

  21. 40

    35

    Returns: {22, 17 }

  22. 40

    36

    Returns: {17, 18 }

  23. 40

    38

    Returns: {18, 19 }

  24. 40

    41

    Returns: {19, 20 }

  25. 40

    42

    Returns: {19, 20 }

  26. 40

    43

    Returns: {19, 20 }

  27. 40

    44

    Returns: {19, 20 }

  28. 45

    1

    Returns: {44, 0 }

  29. 45

    10

    Returns: {4, 5 }

  30. 45

    43

    Returns: {23, 21 }

  31. 45

    44

    Returns: {21, 22 }

  32. 45

    46

    Returns: {22, 23 }

  33. 45

    47

    Returns: {22, 24 }

  34. 45

    50

    Returns: {22, 27 }

  35. 35

    40

    Returns: {17, 22 }

  36. 36

    40

    Returns: {17, 18 }

  37. 38

    40

    Returns: {18, 19 }

  38. 41

    40

    Returns: {19, 20 }

  39. 42

    40

    Returns: {19, 20 }

  40. 43

    40

    Returns: {19, 20 }

  41. 44

    40

    Returns: {19, 20 }

  42. 1

    45

    Returns: {0, 44 }

  43. 10

    45

    Returns: {4, 5 }

  44. 43

    45

    Returns: {21, 23 }

  45. 44

    45

    Returns: {21, 22 }

  46. 46

    45

    Returns: {23, 22 }

  47. 47

    45

    Returns: {24, 22 }

  48. 50

    45

    Returns: {27, 22 }

  49. 2

    10

    Returns: {0, 1 }

  50. 10

    2

    Returns: {0, 1 }

  51. 2

    11

    Returns: {0, 1 }

  52. 11

    2

    Returns: {0, 1 }

  53. 5000

    5000

    Returns: {2499, 2500 }

  54. 5000

    4999

    Returns: {2500, 2499 }

  55. 4999

    5000

    Returns: {2499, 2500 }

  56. 4998

    5000

    Returns: {2498, 2499 }

  57. 5000

    4998

    Returns: {2498, 2499 }

  58. 4999

    4997

    Returns: {2500, 2498 }

  59. 4999

    4999

    Returns: {2499, 2499 }

  60. 4997

    4999

    Returns: {2498, 2500 }

  61. 1

    5000

    Returns: {0, 4999 }

  62. 5000

    1

    Returns: {4999, 0 }

  63. 5000

    2

    Returns: {0, 1 }

  64. 2

    5000

    Returns: {0, 1 }

  65. 4096

    2048

    Returns: {1023, 1024 }

  66. 4095

    2047

    Returns: {3071, 1023 }

  67. 2003

    4999

    Returns: {1001, 3997 }

  68. 4954

    4999

    Returns: {2476, 2477 }

  69. 3

    99

    Returns: {1, 97 }

  70. 4999

    4899

    Returns: {2549, 2449 }

  71. 1353

    4629

    Returns: {676, 3952 }

  72. 2

    3

    Returns: {0, 1 }

  73. 3

    5

    Returns: {1, 3 }

  74. 4901

    2283

    Returns: {3759, 1141 }

  75. 3

    2

    Returns: {0, 1 }

  76. 3

    5000

    Returns: {1, 4998 }

  77. 2

    20

    Returns: {0, 1 }

  78. 2

    5

    Returns: {0, 1 }

  79. 15

    1

    Returns: {14, 0 }

  80. 359

    4888

    Returns: {179, 4708 }

  81. 10

    1

    Returns: {9, 0 }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: