#P4380. [USACO18OPEN] Multiplayer Moo S
[USACO18OPEN] Multiplayer Moo S
Description
The cows have invented a new game, and surprisingly, they gave it the least creative name: "Moo". The Moo game is played on a board consisting of square cells. A cow can claim a cell by shouting "Moo!" and then writing her numeric ID in that cell.
At the end of the game, each cell contains a number. At that point, if a cow has created a region of connected cells and that region is at least as large as every other region, then that cow wins. A "region" is defined as a set of cells with the same numeric ID, where each cell is directly adjacent (up, down, left, or right) to another cell in the same region (diagonals do not count).
Since playing solo can be a bit boring, the cows are also interested in playing in two-cow teams. Two cows on the same team can form a region, but now the cells in the region may belong to either cow on the team.
Given the final state of the game board, please help the cows compute:
- The number of cells in the largest region owned by any single cow.
- The number of cells in the largest region owned by any team of two cows.
Note that a region owned by two cows must contain IDs from both cows on the team; it cannot contain only one cow’s ID.
Input Format
The first line contains (). Each of the next lines contains integers (each in the range ), describing the final state of the board. The board contains at least two distinct numbers.
Output Format
Output two lines: the first line is the size of the largest region owned by any single cow, and the second line is the size of the largest region owned by any two-cow team.
4
2 3 9 3
4 9 9 1
9 9 1 7
2 1 1 9
5
10
Hint
In this example, the largest single-cow region consists of five s. If cows with IDs and form a team, they can form a region of size .
Problem by: Brian Dean.
Translated by ChatGPT 5
京公网安备 11011102002149号