Connection Status:
Competition Arena > Cryptography
SRM 480 · 2009-11-12 · by dolphinigle · Encryption/Compression, Math, Sorting
Class Name: Cryptography
Return Type: long
Method Name: encrypt
Arg Types: (vector<int>)
Problem Statement

Problem Statement

TopCoder Security Agency (TSA, established today) has just invented a new encryption system! This encryption system takes as its input a list of numbers to encrypt.

You work at TSA and your task is to implement a very important part of the encryption process. You are allowed to pick one number in the input list and increment its value by 1. This should be done in such way that the product of all numbers in the list after this change becomes as large as possible.

Given the list of numbers as int[] numbers, return the maximum product you can obtain. It is guaranteed that the return value will not exceed 2^62.

Constraints

  • numbers will contain between 2 and 50 elements, inclusive.
  • Each element of numbers will be between 1 and 1000, inclusive.
  • The return value will not exceed 2^62.
Examples
0)
{1,2,3}
Returns: 12

If we increment the first number, we get 2*2*3 = 12. If we increment the second, we get 1*3*3 = 9. If we increment the third, we get 1*2*4 = 8. Hence, the correct return value is 12.

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

The elements of numbers are not necessarily unique.

2)
{1000,999,998,997,996,995}
Returns: 986074810223904000

The answer may be very big, but will not exceed 2^62.

3)
{1,1,1,1}
Returns: 2
4)
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
Returns: 2615348736000

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

Coding Area

Language: C++17 · define a public class Cryptography with a public method long long encrypt(vector<int> numbers) · 133 test cases · 2 s / 256 MB per case

Submitting as anonymous