Back
Close

WPA: Virus Spreading

Statement
Given a 2-dimensional [[array]], the [[width]] and [[height]] of the array, and the virus' [[strength]], calculate the number of days when all elements are zero. *Steps to calculate the number of days of an array: - Step 1: Assign [[days]] = 0 - Step 2: Check if all the elements are zero. If yes then print [[days]] and end the execution, else increment [[days]] - Step 3: For each [[element]], count how many zero-element around them (and you can store it in another 2d-array) - Step 4: Take the numbers of zero-element of each element accordingly times the [[strength]] (Again, you can store it in 2d-array) - Step 5: For each element, take the element - the result in step 4 accordingly. If the result in step 5 are smaller than {{0}} then assign it to {{0}}. Otherwise, assign according to what value it holds (In other words, assign the result of step 5 if the result is larger or equal to 0) - Step 6: Go to Step 2 *Note, the virus only spreads through the elements around them, not diagonally-infection.

Input description
<<Line 1:>> [[width]], [[height]], [[strength]] <<Next [[height]] lines:>> Contains [[width]] numbers of elements

Output description
<<Line 1:>> The number of days of the array

Constraints
All [[HP]] >= 0 and every input have at least a zero-element

Game modes
Fastest, Shortest

Test cases
Small groups Test
Input
3 2 3 8 10 0 5 3 4
Output
6

Small groups (Part 2) Validator
Input
3 4 6 6 0 12 2 7 17 0 9 6 9 11 10
Output
4

At the corner (Only one) Test
Input
4 3 5 15 23 18 0 21 22 29 30 4 19 27 5
Output
14

At the corner (Part 2) Validator
Input
5 4 10 0 57 60 54 0 31 25 29 27 32 48 30 28 37 22 0 51 39 35 0
Output
9

Only 0 Test
Input
1 1 1 0
Output
0

Only 0 (Part 2) Validator
Input
3 3 21 0 0 0 0 0 0 0 0 0
Output
0

Only 1 line Test
Input
3 1 3 1 2 0
Output
2

Only 1 line (Part 2) Validator
Input
2 1 1 0 1
Output
1

Solution language

Solution

Stub generator input