CF353B.Two Heaps

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.

Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.

Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?

瓦列拉有 2⋅n2\cdot n 个立方体,每个立方体上写有一个从 1010 到 9999 的整数。他任意选择 nn 个立方体放入第一堆,其余立方体构成第二堆。

瓦列拉决定用这些立方体进行游戏。在游戏过程中,他从第一堆中取出一个立方体,并写下其上的数字;然后从第二堆中取出一个立方体,并将其上的两位数字写在之前已写下的两位数字右侧(即拼接在右侧)。最终,他得到一个四位整数:该数的前两位来自第一堆中取出的立方体,后两位来自第二堆中取出的立方体。

瓦列拉非常精通算术,因此他能轻易计算出游戏中所能得到的不同四位整数的个数。另一个问题是:如何将这些立方体划分为两堆(每堆 nn 个),使得这个数值(即瓦列拉所能得到的不同四位整数的个数)尽可能大?

输入格式

The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers a__i (10 ≤ a__i ≤ 99), denoting the numbers on the cubes.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)。第二行包含 2⋅n2 \cdot n 个用空格分隔的整数 aia_i(10≤ai≤9910 \leq a_i \leq 99),表示立方体上的数字。

输出格式

In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers b__i (1 ≤ b__i ≤ 2). The numbers mean: the i-th cube belongs to the b__i-th heap in your division.

If there are multiple optimal ways to split the cubes into the heaps, print any of them.

第一行输出一个整数——Valera 能够得到的互不相同的四位数的最大可能个数。
第二行输出 2⋅n2\cdot n 个数 bib_i(1≤bi≤21\le b_i\le 2)。这些数表示:在你的划分方案中,第 ii 个立方体属于第 bib_i 堆。

如果存在多种最优的将立方体划分为两堆的方式,输出任意一种即可。

输入输出样例

  • 输入#1

    1
    10 99

    输出#1

    1
    2 1
  • 输入#2

    2
    13 24 13 45

    输出#2

    4
    1 2 2 1

说明/提示

In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.

In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.

在第一个测试用例中,瓦莱拉可以将第一个立方体放入第一堆,第二个立方体放入第二堆。此时他得到的数为 10991099。如果他将第二个立方体放入第一堆,第一个立方体放入第二堆,则他可以得到数 99109910。在这两种情况下,不同整数的最大个数均为 11。

在第二个测试用例中,瓦莱拉可以得到数 1313, 1345, 2413, 24451313,\ 1345,\ 2413,\ 2445。注意,如果他将第一个和第三个立方体都放入第一堆,则只能得到两个数:13241324 和 13451345。

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

首页