Statistics

Problem Statement for "PublicTransit"

Problem Statement

Note that this problem has a time limit of 5 seconds.

The city of Gridlock is a grid of cells with R rows and C columns. Each cell has up to four neighbours: the cells directly above, below, to the left, and to the right. A citizen of Gridlock can travel from a cell to any of its neighbours in one minute.

The citizens of Gridlock are upset that it takes too long to get around, so they have decided to build a teleporter. The teleporter will consist of two identical booths, each located in some cell. If a citizen enters either booth, he or she may choose to teleport to the other booth instantly. It is allowed to build both booths in the same cell.

We define the distance between two cells as the minimum number of minutes needed to get from one cell to another. Let D be the maximum distance between any two cells. Place the teleporter in such a way that D is minimized, and return this minimum value.

Definition

Class:
PublicTransit
Method:
minimumLongestDistance
Parameters:
int, int
Returns:
int
Method signature:
int minimumLongestDistance(int R, int C)
(be sure your method is public)

Constraints

  • R is between 1 and 10, inclusive.
  • C is between 1 and 10, inclusive.

Examples

  1. 4

    1

    Returns: 1

    The optimal solution is to connect cell (1, 1) to cell (4, 1). (All cell coordinates are 1-based.)

  2. 2

    2

    Returns: 1

  3. 5

    3

    Returns: 4

  4. 8

    2

    Returns: 4

  5. 1

    1

    Returns: 0

  6. 2

    1

    Returns: 0

  7. 1

    3

    Returns: 1

  8. 4

    1

    Returns: 1

  9. 1

    5

    Returns: 2

  10. 1

    6

    Returns: 2

  11. 7

    1

    Returns: 3

  12. 8

    1

    Returns: 3

  13. 9

    1

    Returns: 4

  14. 1

    10

    Returns: 4

  15. 2

    2

    Returns: 1

  16. 2

    3

    Returns: 2

  17. 4

    2

    Returns: 2

  18. 5

    2

    Returns: 3

  19. 6

    2

    Returns: 3

  20. 2

    7

    Returns: 4

  21. 2

    8

    Returns: 4

  22. 9

    2

    Returns: 5

  23. 2

    10

    Returns: 5

  24. 3

    3

    Returns: 3

  25. 4

    3

    Returns: 3

  26. 5

    3

    Returns: 4

  27. 6

    3

    Returns: 4

  28. 7

    3

    Returns: 5

  29. 3

    8

    Returns: 5

  30. 3

    9

    Returns: 6

  31. 10

    3

    Returns: 6

  32. 4

    4

    Returns: 4

  33. 4

    5

    Returns: 5

  34. 4

    6

    Returns: 5

  35. 4

    7

    Returns: 6

  36. 8

    4

    Returns: 6

  37. 4

    9

    Returns: 7

  38. 10

    4

    Returns: 7

  39. 5

    5

    Returns: 6

  40. 5

    6

    Returns: 6

  41. 5

    7

    Returns: 7

  42. 8

    5

    Returns: 7

  43. 5

    9

    Returns: 8

  44. 5

    10

    Returns: 8

  45. 6

    6

    Returns: 7

  46. 7

    6

    Returns: 8

  47. 8

    6

    Returns: 8

  48. 9

    6

    Returns: 9

  49. 10

    6

    Returns: 9

  50. 7

    7

    Returns: 9

  51. 7

    8

    Returns: 9

  52. 7

    9

    Returns: 10

  53. 10

    7

    Returns: 10

  54. 8

    8

    Returns: 10

  55. 8

    9

    Returns: 11

  56. 8

    10

    Returns: 11

  57. 9

    9

    Returns: 12

  58. 10

    9

    Returns: 12

  59. 10

    10

    Returns: 13

  60. 9

    10

    Returns: 12

  61. 3

    5

    Returns: 4

  62. 1

    4

    Returns: 1


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: