A14743 | The Cells on the Paper
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
On an endless checkered sheet of paper, $n$ cells are chosen and colored in three colors, where $n$ is divisible by $3$ . It turns out that there are exactly $\frac{n}{3}$ marked cells of each of three colors!
Find the largest such $k$ that it's possible to choose $\frac{k}{3}$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold:
- No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $0$ .
- The $i$ -th rectangle contains all the chosen cells of the $i$ -th color and no chosen cells of other colors, for $i = 1, 2, 3$ .
Find the largest such $k$ that it's possible to choose $\frac{k}{3}$ cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold:
- No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be $0$ .
- The $i$ -th rectangle contains all the chosen cells of the $i$ -th color and no chosen cells of other colors, for $i = 1, 2, 3$ .
输入格式
The first line of the input contains a single integer $n$ — the number of the marked cells ( $3 \leq n \le 10^5$ , $n$ is divisible by 3).
The $i$ -th of the following $n$ lines contains three integers $x_i$ , $y_i$ , $c_i$ ( $|x_i|,|y_i| \leq 10^9$ ; $1 \leq c_i \leq 3$ ), where $(x_i, y_i)$ are the coordinates of the $i$ -th marked cell and $c_i$ is its color.
It's guaranteed that all cells $(x_i, y_i)$ in the input are distinct, and that there are exactly $\frac{n}{3}$ cells of each color.
The $i$ -th of the following $n$ lines contains three integers $x_i$ , $y_i$ , $c_i$ ( $|x_i|,|y_i| \leq 10^9$ ; $1 \leq c_i \leq 3$ ), where $(x_i, y_i)$ are the coordinates of the $i$ -th marked cell and $c_i$ is its color.
It's guaranteed that all cells $(x_i, y_i)$ in the input are distinct, and that there are exactly $\frac{n}{3}$ cells of each color.
输出格式
Output a single integer $k$ — the largest number of cells you can leave.
输入输出样例
输入 #1
9 2 3 1 4 1 2 2 1 3 3 4 1 5 3 2 4 4 3 2 4 1 5 2 2 3 5 3
输出 #1
6
输入 #2
3 1 1 1 2 2 2 3 3 3
输出 #2
3
In the first sample, it's possible to leave $6$ cells with indexes $1, 5, 6, 7, 8, 9$ .
In the second sample, it's possible to leave $3$ cells with indexes $1, 2, 3$ .
In the second sample, it's possible to leave $3$ cells with indexes $1, 2, 3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted