Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi/főiskolai kategória, 2016. december 4.

December 4, 2016 10:10 AM – December 4, 2016 3:10 PM

AlphaGo

Peter is a math genius. He is very quick at computing a complicated problem, in particular, he is very good at integer multiplication. Given a sequence of integer numbers, he can quickly tell you the products of all subsequences of the given integers.

But now Peter has a challenger. Larry Page, the cofounder of Google, got jealous of Peter's ability, hence he has ordered Google AlphaGo to compete in a game with Peter. The game is rather simple: each player gets a sequence of integers, then each playes has to determine the maximum product value of all possible subsequences of consecutive numbers from the given sequence. The winner is the one that gives the answer first.

AlphaGo is very good at this game with its advanced algorithm of the combination of machine learning and tree search techniques. Write a program to help Peter win this game. The program must find the required product value quickly. Warning: be careful when you write the program since the input sequence can be quite long.

Input Specification

The input contains sequences of numbers. Each number will have at most 5 digits. There will be at most 100 numbers in each sequence. Each sequence starts in a new line and may continue in several subsequent lines. Each sequence ends with the number –999999 (which is not a part of the sequence).

Output Specification

For each test case, output in one line the maximum product value of all possible subsequences of consecutive numbers from the given sequence.

Sample Input

  1. 1 2 3 -999999
  2. -5 -2 2 -30 -999999
  3. -8 -999999
  4. -1 0 -2 -999999
download as text file

Output for Sample Input

  1. 6
  2. 120
  3. -8
  4. 0
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019