Connection Status:
Competition Arena > LittleElephantAndDouble
SRM 597 · 2013-06-25 · by Witaliy · Greedy, Simple Search, Iteration
Class Name: LittleElephantAndDouble
Return Type: String
Method Name: getAnswer
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Little Elephant from the Zoo of Lviv likes integers.

You are given an int[] A. On a single turn, Little Elephant can double (i.e., multiply by 2) any element of A. He may double the same element more than once, if he wants to. He wants to obtain an array in which all elements are equal. Return "YES" (quotes for clarity) if it is possible to do that and "NO" otherwise.

Notes

  • The return value is case-sensitive. Make sure that you return the exact strings "YES" and "NO".

Constraints

  • A will contain between 1 and 50 elements, inclusive.
  • Each element of A will be between 1 and 1,000,000,000, inclusive.
Examples
0)
{1, 2}
Returns: "YES"

One possible way of making all elements equal is to double the element at index 0.

1)
{1, 2, 3}
Returns: "NO"

It's impossible to make all three elements equal in this case.

2)
{4, 8, 2, 1, 16}
Returns: "YES"
3)
{94, 752, 94, 376, 1504}
Returns: "YES"
4)
{148, 298, 1184}
Returns: "NO"

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

Coding Area

Language: C++17 · define a public class LittleElephantAndDouble with a public method string getAnswer(vector<int> A) · 121 test cases · 2 s / 256 MB per case

Submitting as anonymous