C - Traveling Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300300

問題文

シカのAtCoDeerくんは二次元平面上で旅行をしようとしています。 AtCoDeerくんの旅行プランでは、時刻 00 に 点 (0,0)(0,0) を出発し、 11 以上 NN 以下の各 ii に対し、時刻 tit_i に 点 (xi,yi)(x_i,y_i) を訪れる予定です。

AtCoDeerくんが時刻 tt に 点 (x,y)(x,y) にいる時、 時刻 t+1t+1 には 点 (x+1,y)(x+1,y), (x1,y)(x-1,y), (x,y+1)(x,y+1), (x,y1)(x,y-1) のうちいずれかに存在することができます。 その場にとどまることは出来ないことに注意してください。 AtCoDeerくんの旅行プランが実行可能かどうか判定してください。

制約

  • 11 NN 10510^5
  • 00 xix_i 10510^5
  • 00 yiy_i 10510^5
  • 11 tit_i 10510^5
  • tit_i << ti+1t_{i+1} (11 ii N1N-1)
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN
t1t_1 x1x_1 y1y_1
t2t_2 x2x_2 y2y_2
::
tNt_N xNx_N yNy_N

出力

旅行プランが実行可能ならYesを、不可能ならNoを出力してください。


入力例 1Copy

Copy
2
3 1 2
6 1 1

出力例 1Copy

Copy
Yes

例えば、(0,0)(0,0), (0,1)(0,1), (1,1)(1,1), (1,2)(1,2), (1,1)(1,1), (1,0)(1,0), (1,1)(1,1) と移動すればよいです。


入力例 2Copy

Copy
1
2 100 100

出力例 2Copy

Copy
No

(0,0)(0,0) にいる状態から 22 秒後に (100,100)(100,100) にいるのは不可能です。


入力例 3Copy

Copy
2
5 1 1
100 1 1

出力例 3Copy

Copy
No

Score : 300300 points

Problem Statement

AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0,0)(0, 0) at time 00, then for each ii between 11 and NN (inclusive), he will visit point (xi,yi)(x_i,y_i) at time tit_i.

If AtCoDeer is at point (x,y)(x, y) at time tt, he can be at one of the following points at time t+1t+1: (x+1,y)(x+1,y), (x1,y)(x-1,y), (x,y+1)(x,y+1) and (x,y1)(x,y-1). Note that he cannot stay at his place. Determine whether he can carry out his plan.

Constraints

  • 11 NN 10510^5
  • 00 xix_i 10510^5
  • 00 yiy_i 10510^5
  • 11 tit_i 10510^5
  • tit_i << ti+1t_{i+1} (11 ii N1N-1)
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN
t1t_1 x1x_1 y1y_1
t2t_2 x2x_2 y2y_2
::
tNt_N xNx_N yNy_N

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.


Sample Input 1Copy

Copy
2
3 1 2
6 1 1

Sample Output 1Copy

Copy
Yes

For example, he can travel as follows: (0,0)(0,0), (0,1)(0,1), (1,1)(1,1), (1,2)(1,2), (1,1)(1,1), (1,0)(1,0), then (1,1)(1,1).


Sample Input 2Copy

Copy
1
2 100 100

Sample Output 2Copy

Copy
No

It is impossible to be at (100,100)(100,100) two seconds after being at (0,0)(0,0).


Sample Input 3Copy

Copy
2
5 1 1
100 1 1

Sample Output 3Copy

Copy
No


2025-04-07 (Mon)
18:59:22 +00:00