QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#15617. Tatami Renovation

統計

这座城市的美术馆以其长长的笔直走廊和沿途装饰的艺术瓷砖而闻名。走廊是一个宽 2 米的矩形区域,被划分为若干个 1 米见方的单元格。每个单元格要么放置了一块瓷砖,要么是空的。

作为美术馆翻新工程的一部分,所有空单元格都将铺上榻榻米,这是一种传统的日本地板垫。每块榻榻米的大小为 1 米乘 2 米,因此每块榻榻米恰好覆盖两个相邻的单元格。榻榻米之间不能重叠,且不能覆盖任何瓷砖。

根据瓷砖的初始摆放位置,可能无法用榻榻米覆盖所有空单元格。为了解决这个问题,美术馆允许将每块瓷砖从其原始位置移动到与其共享一条边的相邻单元格中,但不能移动得更远。瓷砖不得移出走廊范围。移动后,单个单元格内不得放置超过一块瓷砖。

图 A.1. 样例输入 1 翻新前后的对比

左图显示了样例输入 1 中瓷砖的初始位置,右图显示了移动一块瓷砖并铺设榻榻米以覆盖所有空单元格的一种可能方式。

请确定在适当移动部分(可能为零)瓷砖的情况下,是否有可能用榻榻米覆盖所有空单元格。如果可能,请找出需要移动的瓷砖的最小数量。

输入格式

输入包含单个测试用例,格式如下:

$n$ $l$ $r_1$ $c_1$ $r_2$ $c_2$ $\vdots$ $r_n$ $c_n$

整数 $n$ ($1 \le n \le 10^5$) 表示走廊中瓷砖的数量。整数 $l$ ($3 \le l \le 10^{18}$) 表示走廊的长度(单位:米)。每对整数 $r_i$ 和 $c_i$ ($i = 1, \dots, n$) 满足 $1 \le r_i \le 2$ 且 $1 \le c_i \le l$,表示第 $i$ 块瓷砖的位置。具体而言,如果将走廊视为一个高为 2 个单元格、宽为 $l$ 个单元格的矩形,则第 $i$ 块瓷砖位于从上往下第 $r_i$ 行、从左往右第 $c_i$ 列。保证所有瓷砖初始时位于不同的单元格中。

输出格式

如果可以通过适当移动部分(可能为零)瓷砖,用榻榻米覆盖走廊中所有的空单元格,则输出需要移动的瓷砖的最小数量。否则,输出 no

样例

输入 1

4 5
2 3
1 4
1 5
2 1

输出 1

1

输入 2

1 3
1 1

输出 2

no

输入 3

6 1000000000000
1 2
1 3
1 4
2 1
2 2
2 3

输出 3

3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.