CF1608E.The Cells on the Paper

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

On an endless checkered sheet of paper, nn cells are chosen and colored in three colors, where nn is divisible by 33. It turns out that there are exactly n3\frac{n}{3} marked cells of each of three colors!

Find the largest such kk that it's possible to choose k3\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 00.
  • The ii-th rectangle contains all the chosen cells of the ii-th color and no chosen cells of other colors, for i=1,2,3i = 1, 2, 3.

在一张无限大的方格纸上,选取 nn 个格子并用三种颜色染色,其中 nn 是 33 的倍数。结果发现,每种颜色恰好有 n3\frac{n}{3} 个被染色的格子!

求最大的 kk,使得可以从中选出每种颜色各 k3\frac{k}{3} 个格子,移除其余所有被染色的格子,然后选取三个边与网格线平行的矩形,满足以下条件:

  • 任意两个矩形不能相交(但可共享边界的一部分)。即:任意两个矩形的交集面积必须为 00。
  • 第 ii 个矩形(i=1,2,3i = 1, 2, 3)恰好包含所选出的第 ii 种颜色的所有格子,且不包含所选出的其他颜色的任何格子。

输入格式

The first line of the input contains a single integer nn — the number of the marked cells (3≤n≤1053 \leq n \le 10^5, nn is divisible by 3).

The ii-th of the following nn lines contains three integers xix_i, yiy_i, cic_i (∣xi∣,∣yi∣≤109|x_i|,|y_i| \leq 10^9; 1≤ci≤31 \leq c_i \leq 3), where (xi,yi)(x_i, y_i) are the coordinates of the ii-th marked cell and cic_i is its color.

It's guaranteed that all cells (xi,yi)(x_i, y_i) in the input are distinct, and that there are exactly n3\frac{n}{3} cells of each color.

输入的第一行包含一个整数 nn —— 标记格子的数量(3≤n≤1053 \leq n \le 10^5,且 nn 能被 33 整除)。

接下来的 nn 行中,第 ii 行包含三个整数 xix_i、yiy_i、cic_i(∣xi∣,∣yi∣≤109|x_i|,|y_i| \leq 10^9;1≤ci≤31 \leq c_i \leq 3),其中 (xi,yi)(x_i, y_i) 是第 ii 个标记格子的坐标,cic_i 是其颜色。

保证输入中所有格子 (xi,yi)(x_i, y_i) 互不相同,且每种颜色的格子数量恰好为 n3\frac{n}{3}。

输出格式

Output a single integer kk — the largest number of cells you can leave.

输出一个整数 kk —— 你能保留的最多格子数。

输入输出样例

  • 输入#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 66 cells with indexes 1,5,6,7,8,91, 5, 6, 7, 8, 9.

In the second sample, it's possible to leave 33 cells with indexes 1,2,31, 2, 3.

在第一个样例中,可以保留索引为 1,5,6,7,8,91, 5, 6, 7, 8, 9 的 66 个格子。

在第二个样例中,可以保留索引为 1,2,31, 2, 3 的 33 个格子。

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

首页