## COCI '14 Contest 2 #5 Šuma

View as PDF

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 128M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Mirko lives in a big enchanted forest where trees are very tall and grow really quickly. That forest can be represented as an matrix where each field contains one tree.

Mirko is very fond of the trees in the enchanted forest. He spent years observing them and for each tree measured how many meters it grew in a year. The trees grow continuously. In other words, if the tree grows 5 meters in a year, it will grow 2.5 meters in half a year.

Apart from trees, Mirko likes mushrooms from the enchanted forest. Sometimes, he eats suspicious colorful mushrooms and starts thinking about peculiar questions. Yesterday, this unfortunate thing happened and he wondered what would be the size of the largest connected group of trees that are all of equal height if the trees continue to grow at the same speed they're growing at that moment.

Mirko quickly measured the current height of all trees in the forest and asked you to answer his question.

Two trees are adjacent if their fields in the matrix share a common edge.
Two trees are connected if there is a sequence of adjacent trees that leads from the first to the second.
A group of trees is connected if every pair of trees in the group is connected.

#### Input Specification

The first line of input contains the integer .

After the first line, lines follow, each of them containing integers.

The line contains integers , the initial height of tree in the row and column, given in meters.

After that, more lines follow with integers.

The line contains integers , the growth speed of the tree in the row and column, given in meters.

Warning: Please use faster input methods because the amount of input is very large. (For example, use scanf instead of cin in C++ or BufferedReader instead of Scanner in Java).

#### Output Specification

The first and only line of output must contain the required number from the task.

#### Scoring

In test cases worth 30% of total points, it will hold .

#### Sample Input 1

3
1 2 3
3 2 2
5 2 1
3 2 1
1 2 1
1 2 3

#### Sample Output 1

7

#### Sample Input 2

2
3 1
3 3
2 5
2 5

#### Sample Output 2

3

#### Explanation of Output for Sample Input 2

After 8 months (two thirds of a year), the trees located at , and will be meters in height.

• commented on March 7, 2015, 12:16 p.m.

The explanation for output should be for sample 2, not 1.

• commented on March 7, 2015, 12:40 p.m.

Fixed.

• commented on Nov. 29, 2014, 10:56 p.m.

MLE every day