Felix Halim .NET  
Google 

Problem Statement

Let's call a rectangular matrix monotonous if in every row and every column each element is greater than the previous one (ai,j < ai + 1,j and ai,j < ai,j + 1). Given four ints - n, m, row and col - return a monotonous rectangular matrix with n rows and m columns which contains all integers between 0 and (n*m - 1) as elements, and the element (row, col) is as small as possible. All indices are 0-based. If there are several solutions, return the lexicographically smallest (see notes). For example, if n = 4, m = 5, row = 3 and col = 3, the matrix is:

 0  1  2  3 16
 4  5  6  7 17
 8  9 10 11 18
12 13 14 15 19

Return the matrix as a String[] where the i-th element represents the i-th row. Each row should be represented as a single space separated list of the values within the row.

Definition

Class:              MatrixConstructor
Method:             construct
Parameters:         int, int, int, int
Returns:            String[]
Method signature:	String[] construct(int n, int m, int row, int col)
(be sure your method is public)

Notes

The rectangular nxm matrix A is lexicographically smaller than the matrix B if and and only if the vector (A0,0, A0,1, ..., A0,m-1, A1,0, A1,1, ..., A1,m-1, ..., An-1,0, An-1,1, ..., An-1,m-1) is lexicographically smaller than the vector (B0,0, B0,1, ..., B0,m-1, B1,0, B1,1, ..., B1,m-1, ..., Bn-1,0, Bn-1,1, ..., Bn-1,m-1).

Constraints

  • n will be between 1 and 10, inclusive.
  • m will be between 1 and 10, inclusive.
  • row will be between 0 and n-1, inclusive.
  • col will be between 0 and m-1, inclusive.

Examples

0)

4
5
3
3
Returns: {"0 1 2 3 16", "4 5 6 7 17", "8 9 10 11 18", "12 13 14 15 19" }
This test is from the problem statement.

1)

4
5
2
1
Returns: {"0 1 6 7 8", "2 3 9 10 11", "4 5 12 13 14", "15 16 17 18 19" }

2)

1
1
0
0
Returns: {"0" }

3)

10
10
9
9
Returns: 
{"0 1 2 3 4 5 6 7 8 9",
 "10 11 12 13 14 15 16 17 18 19",
 "20 21 22 23 24 25 26 27 28 29",
 "30 31 32 33 34 35 36 37 38 39",
 "40 41 42 43 44 45 46 47 48 49",
 "50 51 52 53 54 55 56 57 58 59",
 "60 61 62 63 64 65 66 67 68 69",
 "70 71 72 73 74 75 76 77 78 79",
 "80 81 82 83 84 85 86 87 88 89",
 "90 91 92 93 94 95 96 97 98 99" }

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.


Google India Code Jam 2006 - Table of Contents

  1. Main Page - Google India Code Jam 2006
  2. Qualification Round
  3. Elimination Round
  4. Championship Round
  5. Links/Blogs/News

© Felix Halim 2009 (Loaded in 0.01087 secs)