Log inSign up
Problems / A002

Tending the flower bed

200 ptsCases 18Set by dongbinna
Added October 30.

Statement

There is a flower bed in the form of a 2D array with N rows and N columns. At the start each cell may or may not hold a flower. Each flower has a capacity of its own. The amount of water held by the flower in each cell is 0 at the start. A cell can hold at most one flower.

The keeper who tends the flower bed can use the following two operations.

1. Watering operation

The watering operation comes with a 2D array of N rows and N columns. The natural number at each position is the amount of water that goes into that cell. If a flower is in the cell, the water goes into that flower. If the water the flower now holds is greater than its capacity, the flower in that cell dies and disappears at once. Water that did not get into the flower evaporates and is gone. If water goes into a cell with no flower, the water is stored in that cell.

2. Flower making operation

In a cell that currently holds no flower, a new flower is made if the water there is 10 or more. The capacity of the new flower is (amount of water / 2). The fractional part is discarded. The new flower also starts out holding 0 water.

Given the initial state of the flowers and K operations in total, write a program that runs every operation and then prints, for each cell of the N by N flower bed, whether a flower is there or not. Print 1 where a flower is present and 0 where it is not.

For example, with N=5, suppose the state of the flower bed is given as follows.

02035
00000
73533
99000
00000

Suppose the total number of operations is K=3 and the watering operation runs first. Suppose the given 2D array with N rows and N columns is as follows.

113514
112756
9102120
175835
6791015

The flower bed then looks as follows. Cells that hold a flower are shaded and written as (current water / flower capacity). Cells with no flower are left unshaded and show only (current water).

11051 / 34 / 5
112756
0002 / 30 / 3
1 / 97 / 95835
6791015

After the flower making operation runs, the flower bed looks as follows.

0 / 5051 / 34 / 5
10 / 6756
0002 / 30 / 3
1 / 97 / 9580 / 17
6790 / 50 / 7

Suppose the watering operation now runs again. Suppose the given 2D array with N rows and N columns is as follows.

71264
341073
45777
18593
831275

The flower bed then looks as follows.

01700
44 / 617129
45700
2 / 9010173 / 17
14102105 / 7

Input and Output Examples

Example 1

Input

5, 3, [[0, 2, 0, 3, 5], [0, 0, 0, 0, 0], [7, 3, 5, 3, 3], [9, 9, 0, 0, 0], [0, 0, 0, 0, 0]], [[1], [11, 3, 5, 1, 4], [1, 12, 7, 5, 6], [9, 10, 21, 2, 0], [1, 7, 5, 8, 35], [6, 7, 9, 10, 15], [2], [1], [7, 1, 2, 6, 4], [3, 4, 10, 7, 3], [4, 5, 7, 7, 7], [1, 8, 5, 9, 3], [8, 3, 12, 7, 5]]

Output

[[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 1]]

Example 2

Input

3, 1, [[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1], [2, 0, 2], [0, 0, 0], [2, 0, 2]]

Output

[[0, 1, 0], [1, 1, 1], [0, 1, 0]]

Input

  • First the flower bed size N and the number of operations K are given. N is a natural number of at most 100, and K is a natural number of at most 500.

  • Next comes flowers, a 2D array with N rows and N columns holding the initial state of the flower bed. The value at each position is the water capacity of the flower there. A cell with no flower is given as 0. A cell that is not 0 holds a flower, and the value is that flower's water capacity. The initial capacity at each cell is a natural number of at most 100.

  • Next comes operations, an array holding the information for the K operations. The operation number comes first, as a 1D array with one element, 1 for the watering operation and 2 for the flower making operation. When a watering operation is given, the N rows follow one after another, each as a 1D array. The amount of water given at each cell in a watering operation is 0 or a natural number of at most 100.

Output

  • Write a program that returns a 2D array with N rows and N columns telling whether a flower is present at each cell of the flower bed. Use 1 where a flower is present and 0 where it is not.

Requirements

  • You must write a solution(N, K, flowers, operations) function and return the answer
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 18 cases, and 2 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 18 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

2 public cases. Judging also uses hidden cases. You have to pass all 18 cases to solve this.

Input
Expected output
5, 3, [[0, 2, 0, 3, 5], [0, 0, 0, 0, 0], [7, 3, 5, 3, 3], [9, 9, 0, 0, 0], [0, 0, 0, 0, 0]], [[1], [11, 3, 5, 1, 4], [1, 12, 7, 5, 6], [9, 10, 21, 2, 0], [1, 7, 5, 8, 35], [6, 7, 9, 10, 15], [2], [1], [7, 1, 2, 6, 4], [3, 4, 10, 7, 3], [4, 5, 7, 7, 7], [1, 8, 5, 9, 3], [8, 3, 12, 7, 5]]
[[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 1]]
3, 1, [[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1], [2, 0, 2], [0, 0, 0], [2, 0, 2]]
[[0, 1, 0], [1, 1, 1], [0, 1, 0]]

Notes

Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.

This is problem 2 of practice test 1 in the original.

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 63ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 2 public cases. Submitting runs the hidden cases too.

People who solved this problem

Nobody yet. You could be the first.