#P7150. [USACO20DEC] Stuck in a Rut S
[USACO20DEC] Stuck in a Rut S
Description
Farmer John has recently expanded his farm, and from the cows’ point of view, the farm is basically infinitely large. The cows imagine the grazing area as an infinite two-dimensional grid made of square cells, where every cell contains tasty grass (treat each cell like a square on a chessboard). Farmer John has cows (), each initially in a different cell. Some face north, and some face east.
Every hour, each cow does one of the following:
- If the grass in the cell she is currently in has already been eaten by another cow, then she stops (and stays stopped from that moment on).
- Otherwise, she eats all the grass in her current cell, then moves one cell in the direction she is facing.
After some time, each cow will leave behind a trail of cells where the grass has been eaten.
If two cows move into the same grassy cell during a move, they will share the grass in that cell, and in the next hour they will continue moving in the directions they are facing.
Farmer John is unhappy when he sees cows that stop eating grass, so he wants to know who should be blamed for causing cows to stop. If cow stops on a cell whose grass was previously eaten by cow , then we say cow blocks cow . Furthermore, if cow blocks cow and cow blocks cow , then we also consider cow to block cow (that is, the “blocks” relation is transitive). The amount of blame a cow receives equals the number of cows she blocks. Compute, for each cow, how many cows she is to blame for, i.e., how many cows she blocks.
Input Format
The first line contains . The next lines each describe a cow’s starting position, containing a character N (meaning facing north) or E (meaning facing east), and two non-negative integers and (, ) giving the cell coordinates. All coordinates are distinct, and all coordinates are distinct.
To make directions and coordinates as clear as possible: if a cow is at cell and moves north, she will arrive at cell . If she moves east, she will arrive at cell .
Output Format
Output lines. The -th line should contain the number of cows that the -th cow in the input is to blame for.
6
E 3 5
N 5 3
E 4 6
E 10 4
N 11 1
E 9 2
0
0
1
2
1
0
Hint
In the sample, cow 3 blocks cow 2, cow 4 blocks cow 5, and cow 5 blocks cow 6. By transitivity, cow 4 also blocks cow 6.
- In testdata 2–5, all coordinates are at most .
- In testdata 6–10, there are no additional restrictions.
Problem by: Brian Dean.
Translated by ChatGPT 5
京公网安备 11011102002149号