CF1427C.The Hard Work of Paparazzi

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are a paparazzi working in Manhattan.

Manhattan has rr south-to-north streets, denoted by numbers 1,2,…,r1, 2,\ldots, r in order from west to east, and rr west-to-east streets, denoted by numbers 1,2,…,r1,2,\ldots,r in order from south to north. Each of the rr south-to-north streets intersects each of the rr west-to-east streets; the intersection between the xx-th south-to-north street and the yy-th west-to-east street is denoted by (x,y)(x, y). In order to move from the intersection (x,y)(x,y) to the intersection (x′,y′)(x', y') you need ∣x−x′∣+∣y−y′∣|x-x'|+|y-y'| minutes.

You know about the presence of nn celebrities in the city and you want to take photos of as many of them as possible. More precisely, for each i=1,…,ni=1,\dots, n, you know that the ii-th celebrity will be at the intersection (xi,yi)(x_i, y_i) in exactly tit_i minutes from now (and he will stay there for a very short time, so you may take a photo of him only if at the tit_i-th minute from now you are at the intersection (xi,yi)(x_i, y_i)). You are very good at your job, so you are able to take photos instantaneously. You know that ti<ti+1t_i \lt t_{i+1} for any i=1,2,…,n−1i=1,2,\ldots, n-1.

Currently you are at your office, which is located at the intersection (1,1)(1, 1). If you plan your working day optimally, what is the maximum number of celebrities you can take a photo of?

你是一名在曼哈顿工作的狗仔队记者。

曼哈顿有 rr 条由南向北的街道,从西到东依次编号为 1,2,…,r1, 2,\ldots, r;另有 rr 条由西向东的街道,从南到北依次编号为 1,2,…,r1,2,\ldots,r。每条由南向北的街道均与每条由西向东的街道相交;第 xx 条由南向北的街道与第 yy 条由西向东的街道的交点记为 (x,y)(x, y)。从交点 (x,y)(x,y) 移动到交点 (x′,y′)(x', y') 需要 ∣x−x′∣+∣y−y′∣|x-x'|+|y-y'| 分钟。

你已获悉城中有 nn 位名人,并希望尽可能多地拍摄他们的照片。更准确地说,对每个 i=1,…,ni=1,\dots, n,你知道第 ii 位名人将在当前时刻之后恰好 tit_i 分钟出现在交点 (xi,yi)(x_i, y_i)(且他仅在该处短暂停留,因此你仅当在当前时刻之后的第 tit_i 分钟恰好位于交点 (xi,yi)(x_i, y_i) 时,才能成功为其拍照)。你工作能力极强,可瞬间完成拍照。此外,已知对任意 i=1,2,…,n−1i=1,2,\ldots, n-1,均有 ti<ti+1t_i \lt t_{i+1}。

目前你位于办公室,其位置为交点 (1,1)(1, 1)。若你对当天工作进行最优规划,最多能拍摄多少位名人的照片?

输入格式

The first line of the input contains two positive integers r,nr, n (1≤r≤5001\le r\le 500, 1≤n≤100,0001\le n\le 100,000) – the number of south-to-north/west-to-east streets and the number of celebrities.

Then nn lines follow, each describing the appearance of a celebrity. The ii-th of these lines contains 33 positive integers ti,xi,yit_i, x_i, y_i (1≤ti≤1,000,0001\le t_i\le 1,000,000, 1≤xi,yi≤r1\le x_i, y_i\le r) — denoting that the ii-th celebrity will appear at the intersection (xi,yi)(x_i, y_i) in tit_i minutes from now.

It is guaranteed that ti<ti+1t_i \lt t_{i+1} for any i=1,2,…,n−1i=1,2,\ldots, n-1.

输入的第一行包含两个正整数 r,nr, n(1≤r≤5001\le r\le 500,1≤n≤100,0001\le n\le 100,000)——分别表示由南向北/由西向东的街道数量以及名人的数量。

接下来是 nn 行,每行描述一位名人的出现信息。其中第 ii 行包含三个正整数 ti,xi,yit_i, x_i, y_i(1≤ti≤1,000,0001\le t_i\le 1,000,000,1≤xi,yi≤r1\le x_i, y_i\le r),表示第 ii 位名人将在 tit_i 分钟后出现在坐标为 (xi,yi)(x_i, y_i) 的路口。

保证对任意 i=1,2,…,n−1i=1,2,\ldots, n-1,均有 ti<ti+1t_i \lt t_{i+1}。

输出格式

Print a single integer, the maximum number of celebrities you can take a photo of.

输出一个整数,表示你能合影的名人数目的最大值。

输入输出样例

  • 输入#1

    10 1
    11 6 8

    输出#1

    0
  • 输入#2

    6 9
    1 2 6
    7 5 1
    8 5 5
    10 3 1
    12 4 4
    13 6 2
    17 6 6
    20 1 4
    21 5 4

    输出#2

    4
  • 输入#3

    10 4
    1 2 1
    5 10 9
    13 8 8
    15 9 9

    输出#3

    1
  • 输入#4

    500 10
    69 477 122
    73 186 235
    341 101 145
    372 77 497
    390 117 440
    494 471 37
    522 300 498
    682 149 379
    821 486 359
    855 157 386

    输出#4

    3

说明/提示

Explanation of the first testcase: There is only one celebrity in the city, and he will be at intersection (6,8)(6,8) exactly 1111 minutes after the beginning of the working day. Since you are initially at (1,1)(1,1) and you need ∣1−6∣+∣1−8∣=5+7=12|1-6|+|1-8|=5+7=12 minutes to reach (6,8)(6,8) you cannot take a photo of the celebrity. Thus you cannot get any photo and the answer is 00.

Explanation of the second testcase: One way to take 44 photos (which is the maximum possible) is to take photos of celebrities with indexes 3,5,7,93, 5, 7, 9 (see the image for a visualization of the strategy):

  • To move from the office at (1,1)(1,1) to the intersection (5,5)(5,5) you need ∣1−5∣+∣1−5∣=4+4=8|1-5|+|1-5|=4+4=8 minutes, so you arrive at minute 88 and you are just in time to take a photo of celebrity 33.
  • Then, just after you have taken a photo of celebrity 33, you move toward the intersection (4,4)(4,4). You need ∣5−4∣+∣5−4∣=1+1=2|5-4|+|5-4|=1+1=2 minutes to go there, so you arrive at minute 8+2=108+2=10 and you wait until minute 1212, when celebrity 55 appears.
  • Then, just after you have taken a photo of celebrity 55, you go to the intersection (6,6)(6,6). You need ∣4−6∣+∣4−6∣=2+2=4|4-6|+|4-6|=2+2=4 minutes to go there, so you arrive at minute 12+4=1612+4=16 and you wait until minute 1717, when celebrity 77 appears.
  • Then, just after you have taken a photo of celebrity 77, you go to the intersection (5,4)(5,4). You need ∣6−5∣+∣6−4∣=1+2=3|6-5|+|6-4|=1+2=3 minutes to go there, so you arrive at minute 17+3=2017+3=20 and you wait until minute 2121 to take a photo of celebrity 99.

Explanation of the third testcase: The only way to take 11 photo (which is the maximum possible) is to take a photo of the celebrity with index 11 (since ∣2−1∣+∣1−1∣=1|2-1|+|1-1|=1, you can be at intersection (2,1)(2,1) after exactly one minute, hence you are just in time to take a photo of celebrity 11).

Explanation of the fourth testcase: One way to take 33 photos (which is the maximum possible) is to take photos of celebrities with indexes 3,8,103, 8, 10:

  • To move from the office at (1,1)(1,1) to the intersection (101,145)(101,145) you need ∣1−101∣+∣1−145∣=100+144=244|1-101|+|1-145|=100+144=244 minutes, so you can manage to be there when the celebrity 33 appears (at minute 341341).
  • Then, just after you have taken a photo of celebrity 33, you move toward the intersection (149,379)(149,379). You need ∣101−149∣+∣145−379∣=282|101-149|+|145-379|=282 minutes to go there, so you arrive at minute 341+282=623341+282=623 and you wait until minute 682682, when celebrity 88 appears.
  • Then, just after you have taken a photo of celebrity 88, you go to the intersection (157,386)(157,386). You need ∣149−157∣+∣379−386∣=8+7=15|149-157|+|379-386|=8+7=15 minutes to go there, so you arrive at minute 682+15=697682+15=697 and you wait until minute 855855 to take a photo of celebrity 1010.

第一个测试用例的解释:城市中只有一位名人,他恰好在工作日开始后 1111 分钟出现在交叉路口 (6,8)(6,8)。由于你初始位置为 (1,1)(1,1),而到达 (6,8)(6,8) 所需时间为 ∣1−6∣+∣1−8∣=5+7=12|1-6|+|1-8|=5+7=12 分钟,因此你无法及时赶到 (6,8)(6,8) 拍摄该名人。故你无法获得任何照片,答案为 00。

第二个测试用例的解释:一种可拍摄 44 张照片的方法(这也是可能的最大值)是拍摄编号为 3,5,7,93, 5, 7, 9 的名人(参见下图以直观理解该策略):

  • 从办公室 (1,1)(1,1) 移动到交叉路口 (5,5)(5,5) 需要 ∣1−5∣+∣1−5∣=4+4=8|1-5|+|1-5|=4+4=8 分钟,因此你在第 88 分钟抵达,并恰好来得及拍摄名人 33。
  • 拍摄完名人 33 后,你立即前往交叉路口 (4,4)(4,4)。所需时间为 ∣5−4∣+∣5−4∣=1+1=2|5-4|+|5-4|=1+1=2 分钟,因此你在 8+2=108+2=10 分钟时抵达,并等待至第 1212 分钟,此时名人 55 出现。
  • 拍摄完名人 55 后,你立即前往交叉路口 (6,6)(6,6)。所需时间为 ∣4−6∣+∣4−6∣=2+2=4|4-6|+|4-6|=2+2=4 分钟,因此你在 12+4=1612+4=16 分钟时抵达,并等待至第 1717 分钟,此时名人 77 出现。
  • 拍摄完名人 77 后,你立即前往交叉路口 (5,4)(5,4)。所需时间为 ∣6−5∣+∣6−4∣=1+2=3|6-5|+|6-4|=1+2=3 分钟,因此你在 17+3=2017+3=20 分钟时抵达,并等待至第 2121 分钟,此时名人 99 出现。

第三个测试用例的解释:唯一能拍摄 11 张照片的方法(这也是可能的最大值)是拍摄编号为 11 的名人(因为 ∣2−1∣+∣1−1∣=1|2-1|+|1-1|=1,你可在恰好 11 分钟后抵达交叉路口 (2,1)(2,1),从而恰好来得及拍摄名人 11)。

第四个测试用例的解释:一种可拍摄 33 张照片的方法(这也是可能的最大值)是拍摄编号为 3,8,103, 8, 10 的名人:

  • 从办公室 (1,1)(1,1) 移动到交叉路口 (101,145)(101,145) 需要 ∣1−101∣+∣1−145∣=100+144=244|1-101|+|1-145|=100+144=244 分钟,因此你能在名人 33 出现时(第 341341 分钟)成功抵达该地。
  • 拍摄完名人 33 后,你立即前往交叉路口 (149,379)(149,379)。所需时间为 ∣101−149∣+∣145−379∣=282|101-149|+|145-379|=282 分钟,因此你在 341+282=623341+282=623 分钟时抵达,并等待至第 682682 分钟,此时名人 88 出现。
  • 拍摄完名人 88 后,你立即前往交叉路口 (157,386)(157,386)。所需时间为 ∣149−157∣+∣379−386∣=8+7=15|149-157|+|379-386|=8+7=15 分钟,因此你在 682+15=697682+15=697 分钟时抵达,并等待至第 855855 分钟,此时名人 1010 出现。

输入解题思路,AI测评打分。不知道怎么写?

首页