Connection Status:
Competition Arena > BunnyPuzzle
SRM 463 · 2009-11-12 · by rng_58 · Simple Search, Iteration
Class Name: BunnyPuzzle
Return Type: int
Method Name: theCount
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.

Taro and Hanako are playing Bunny Puzzle. There are several bunnies standing on a line. You are given a int[] bunnies, where each element is the initial position of a single bunny.

They must perform the following routine exactly once:
  1. Choose two different bunnies A and B, located at points a and b, respectively.
  2. A jumps over B and lands at point 2*b-a.




The jump is not allowed if another bunny is already at point 2*b-a.



The jump is also not allowed if A jumps over more than one bunny.





Return the number of different ways in which Taro and Hanako can choose the pair of bunnies A and B. "A jumps over B" and "B jumps over A" are considered to be different.

Constraints

  • bunnies will contain between 2 and 50 elements, inclusive.
  • Each element of bunnies will be between -10^6 and 10^6, inclusive.
  • bunnies will be sorted in strictly ascending order.
Examples
0)
{5, 8}
Returns: 2

There are two possible moves: A bunny jumps from 5 to 11 A bunny jumps from 8 to 2

1)
{-1, 0, 1}
Returns: 2

There are two possible moves: A bunny jumps from 0 to -2 A bunny jumps from 0 to 2

2)
{0, 1, 3}
Returns: 3

There are three possible moves: A bunny jumps from 0 to 2 A bunny jumps from 1 to -1 A bunny jumps from 1 to 5

3)
{-677, -45, -2, 3, 8, 29, 384, 867}
Returns: 7
4)
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Returns: 2

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

Coding Area

Language: C++17 · define a public class BunnyPuzzle with a public method int theCount(vector<int> bunnies) · 45 test cases · 2 s / 256 MB per case

Submitting as anonymous