CF1234B1.Social Network (easy version)

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The only difference between easy and hard versions are constraints on nn and kk.

You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most kk most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 00).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive nn messages, the ii-th message will be received from the friend with ID idiid_i (1≤idi≤1091 \le id_i \le 10^9).

If you receive a message from idiid_i in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with idiid_i on the screen):

  • Firstly, if the number of conversations displayed on the screen is kk, the last conversation (which has the position kk) is removed from the screen.
  • Now the number of conversations on the screen is guaranteed to be less than kk and the conversation with the friend idiid_i is not displayed on the screen.
  • The conversation with the friend idiid_i appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.

Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all nn messages.

简单版本与困难版本的唯一区别在于 nn 和 kk 的约束条件。

你正通过智能手机在某个流行的社交网络上与朋友聊天。你的智能手机最多可显示最近的 kk 个与朋友的对话。初始时,屏幕为空(即显示的对话数量为 00)。

每场对话都发生在你和某位朋友之间。你与任意一位朋友之间至多只存在一场对话。因此,每场对话可由该朋友的 ID 唯一确定。

你(突然地!)拥有了预知未来的能力。你知道当天将收到 nn 条消息,其中第 ii 条消息来自 ID 为 idiid_i 的朋友(1≤idi≤1091 \le id_i \le 10^9)。

  • 若你从 idiid_i 收到一条消息,且当前屏幕上已显示与 idiid_i 的对话,则不发生任何变化:屏幕上的对话及其顺序均保持不变,你阅读该消息后继续等待新消息。
  • 否则(即屏幕上尚未显示与 idiid_i 的对话):
    • 首先,若屏幕上已显示 kk 场对话,则移除屏幕上位置为 kk 的最后一场对话;
    • 此时,屏幕上对话数量一定小于 kk,且与朋友 idiid_i 的对话尚未显示;
    • 与朋友 idiid_i 的对话将出现在屏幕最上方(即位置 11),其余所有已显示的对话均向下移动一个位置。

你的任务是:在处理完全部 nn 条消息后,输出屏幕上对话的列表(按其在屏幕上显示的顺序)。

输入格式

The first line of the input contains two integers nn and kk (1≤n,k≤200)1 \le n, k \le 200) — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains nn integers id1,id2,…,idnid_1, id_2, \dots, id_n (1≤idi≤1091 \le id_i \le 10^9), where idiid_i is the ID of the friend which sends you the ii-th message.

输入的第一行包含两个整数 nn 和 kk(1≤n,k≤2001 \le n, k \le 200)—— 分别表示消息总数以及你的智能手机能够显示的对话数量。

输入的第二行包含 nn 个整数 id1,id2,…,idnid_1, id_2, \dots, id_n(1≤idi≤1091 \le id_i \le 10^9),其中 idiid_i 表示给你发送第 ii 条消息的好友的 ID。

输出格式

In the first line of the output print one integer mm (1≤m≤min(n,k)1 \le m \le min(n, k)) — the number of conversations shown after receiving all nn messages.

In the second line print mm integers ids1,ids2,…,idsmids_1, ids_2, \dots, ids_m, where idsiids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position ii after receiving all nn messages.

在输出的第一行打印一个整数 mm(1≤m≤min⁡(n,k)1 \le m \le \min(n, k))—— 表示接收全部 nn 条消息后所显示的对话数量。

在第二行打印 mm 个整数 ids1,ids2,…,idsmids_1, ids_2, \dots, ids_m,其中 idsiids_i 应等于接收全部 nn 条消息后,位于第 ii 个位置的对话所对应的联系人的 ID。

输入输出样例

  • 输入#1

    7 2
    1 2 3 2 1 3 2

    输出#1

    2
    2 1
  • 输入#2

    10 4
    2 3 3 1 1 2 1 2 3 3

    输出#2

    3
    1 3 2

说明/提示

In the first example the list of conversations will change in the following way (in order from the first to last message):

  • [][];
  • [1][1];
  • [2,1][2, 1];
  • [3,2][3, 2];
  • [3,2][3, 2];
  • [1,3][1, 3];
  • [1,3][1, 3];
  • [2,1][2, 1].

In the second example the list of conversations will change in the following way:

  • [][];
  • [2][2];
  • [3,2][3, 2];
  • [3,2][3, 2];
  • [1,3,2][1, 3, 2];
  • and then the list will not change till the end.

在第一个例子中,对话列表将按以下方式变化(按消息从第一到最后一顺序):

  • [][];
  • [1][1];
  • [2,1][2, 1];
  • [3,2][3, 2];
  • [3,2][3, 2];
  • [1,3][1, 3];
  • [1,3][1, 3];
  • [2,1][2, 1]。

在第二个例子中,对话列表将按以下方式变化:

  • [][];
  • [2][2];
  • [3,2][3, 2];
  • [3,2][3, 2];
  • [1,3,2][1, 3, 2];
  • 此后列表将一直保持不变直至结束。

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

首页