Connection Status:
Competition Arena > MaxPlanting
TCC19 India Qualifiers · 2019-05-04 · by erinn · Brute Force
Class Name: MaxPlanting
Return Type: int
Method Name: most
Arg Types: (int, int, int, int)
Problem Statement

Problem Statement

You are planting some crops in a rectangular field, divided into cells, width by height. Any given cell can have at most one crop growing in it. Any square area of length size can only have at most max crops growing in it. What is the most number of crops that can be grown in the field?

Constraints

  • width will be between 1 and 100, inclusive.
  • height will be between 1 and 100, inclusive.
  • size will be between 1 and MIN(width, height), inclusive.
  • max will be between 1 and 10000, inclusive.
Examples
0)
3
3
2
1
Returns: 4

There are 9 cells in total, but no 2x2 area can have more than one plant. Our best bet is this: X-X --- X-X

1)
3
3
2
2
Returns: 6

Here each 2x2 area can have two crops, so we can do something like this: X-X X-X X-X

2)
10
10
4
5
Returns: 42
3)
3
3
2
3
Returns: 8
4)
3
3
2
5
Returns: 9

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

Coding Area

Language: C++17 · define a public class MaxPlanting with a public method int most(int width, int height, int size, int max) · 35 test cases · 2 s / 256 MB per case

Submitting as anonymous