Connection Status:
Competition Arena > CubeAnts
SRM 507 · 2010-11-01 · by ir5 · Simple Math
Class Name: CubeAnts
Return Type: int
Method Name: getMinimumSteps
Arg Types: (vector<int>)
Problem Statement

Problem Statement

NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.

Fox Ciel is observing the behavior of ants. She has a cube whose vertices are indexed from 0 to 7 as follows.

You are given a int[] pos containing the initial locations of the ants. The i-th element of pos is the index of the vertex where the i-th ant is located. In an attempt to observe their moves, Ciel puts honey on the 0-th vertex. The ants notice it immediately and start moving toward the honey. In a single turn, each ant will either move to an adjacent vertex along an edge of the cube or stay in its current vertex. All moves in a turn happen simultaneously, and at all times, it is legal for multiple ants to be at the same location of the cube.

Ciel observes the ants until they all move to the 0-th vertex. In order to determine how clever they were, she wants to know the minimal number of turns that were required for this to happen. Return this minimal number.

Constraints

  • pos will contain between 1 and 50 elements, inclusive.
  • Each element of pos will be between 0 and 7, inclusive.
Examples
0)
{0,1,1}
Returns: 1
1)
{5,4}
Returns: 2
2)
{0}
Returns: 0

There is only one ant, and it is already on the 0-th vertex, so the minimum number of turns required is 0.

3)
{6,1,6}
Returns: 3
4)
{7,7,3,3,7,7,3,3}
Returns: 2

Submissions are judged against all 89 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CubeAnts with a public method int getMinimumSteps(vector<int> pos) · 89 test cases · 2 s / 256 MB per case

Submitting as anonymous