Connection Status:
Competition Arena > GridGenerator
SRM 256 · 2005-08-02 · by lars2520 · Simple Math
Class Name: GridGenerator
Return Type: int
Method Name: generate
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

Consider the following grid of numbers:
 1 0  3  4   1
 4 5  8  15  20
 1 10 23 46  81
 0 11 44 113 240
 3 14 69 226 579
Aside from the top row and left column, each number is equal to the sum of the three numbers immediately left, above, and above-left of it. You will be given a int[], row, representing the first row of a similar grid, and a int[], col, representing the first column of the grid. Your task is to return the value of the lower rightmost location when the values are calculated in the same way. Hence, the above example would be represented by the input row = {1,0,3,4,1}, col = {1,4,1,0,3}.

Constraints

  • row and col will contain the same number of elements.
  • row and col will contain between 2 and 10 elements, inclusive.
  • Each element of row and col will be between 0 and 9, inclusive.
  • The first element of row will be the same as the first element of col.
Examples
0)
{1,0,3,4,1}
{1,4,1,0,3}
Returns: 579

The example above.

1)
{9,9,9,9,9,9,9,9,9,9}
{9,9,9,9,9,9,9,9,9,9}
Returns: 13163067

The largest possible return.

2)
{0,0,0,0,0,0,0,0,0}
{0,0,0,0,0,0,0,0,0}
Returns: 0
3)
{1,5,3,1,2,9}
{1,3,1,5,9,7}
Returns: 5027
4)
{1,2}
{1,3}
Returns: 6

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

Coding Area

Language: C++17 · define a public class GridGenerator with a public method int generate(vector<int> row, vector<int> col) · 11 test cases · 2 s / 256 MB per case

Submitting as anonymous