RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 R03720

Kunai

설명

Kunai is an acuate weapon used by ninjas whose shape is similar to a knife. Ninjas were attacking their
enemies by throwing kunais against them.
There are N ninjas in a grid of squares with W columns and H rows. Every ninja is in the center of a square,
and no two ninjas share the same square. Each ninja has a kunai, and looks toward one of the four directions; up,
down, left, or right. At time 0, every ninja threw his/her kunai to the direction he/she is looking toward.
Every kunai proceeds straight with speed 1. If more than one kunais come to the same place at the same time,
they clash each other and disappear. The size of a kunai is so small that we can ignore it. Also, since ninjas can
move quickly, they will not be hit by kunais. Each kunai continues to proceed along its direction without losing
its speed unless it is clashed with another kunai.
In the following figures, the arrows represent kunais. The direction of an arrow describes the direction of a
kunai. In these figures, all thick arrows will clash.
On the other hand, in each of the following figures, a thick arrow will not clash with another thick arrow. In
the second and the third figure, a thin arrow clashes with a thick arrow. Because clashed arrows will disappear, a
thick arrow will not clash with another thick arrow in each of these figures.
Task
Count the number of squares in the W ×H grid where kunais pass through after a sufficient amount of time passed.

제약

1 ≦N ≦100 000
The number of ninjas
1 ≦W ≦1 000 000 000, 1 ≦H ≦1 000 000 000
The size of the grid
1 ≦Xi ≦W, 1 ≦Yi ≦H
The coordinates of ninjas

In test cases worth 10% of the full score, N ≦1 000, W ≦1 000, H ≦1 000.
In test cases worth 40% of the full score, N ≦1 000.
Sample Input and Output
Sample Input 1
Sample Output 1
5 4
5
3 3 2
3 2 0
4 2 2
5 4 1
1 1 3
11
In this example, the grid at time 0 is described as follows.

The kunai thrown by the ninja i is denoted by the kunai i. At time 0.5, the kunai 2 and the kunai 3 will clash
each other and disappear. The following figure describes the grid at time 1. Here gray squares denote the squares
where kunais already passed through.
At time 2, the kunai 1 and the kunai 5 will clash each other and disappear. The grid at time 2 is described as
follows.
No more kunais are clashed in a square after time 2. The grid after a sufficient amount of time passed is
described as follows.

Finally, the number of squares in the grid where kunais pass through is 11. Therefore, we should output 11.
Sample Input 2
Sample Output 2
7 6
12
3 2 3
6 3 2
7 1 3
1 5 0
3 6 1
6 6 1
4 5 2
1 3 0
6 5 2
5 1 2
6 4 3
4 1 3
29

입력 형식

Read the following data from the standard input.
• The first line of input contains two space separated integers W, H, which describe the size of the grid.
• The second line of input contains an integer N, the number of ninjas.
• The i-th line (1 ≦i ≦N) of the following N lines contains three space separated integers Xi, Yi, Di, describ-
ing that the position of the ninja i is in the Xi-th column from left and Yi-th row from above. No two ninjas
share the same position. The direction of the ninja i is described by the value of Di.
– When Di = 0, the ninja i is looking toward the right.
– When Di = 1, the ninja i is looking toward the up.
– When Di = 2, the ninja i is looking toward the left.
– When Di = 3, the ninja i is looking toward the down.

출력 형식

Output the number of squares in the W ×H grid where kunais pass through after a sufficient amount of time passed
to the standard output.

문제 정보

rip 작성

출처 APIO 2012

평가 및 의견

Kunai

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Kunai

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8