QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 50

#2534. 灯泡

统计

小薇非常喜欢降临节和圣诞节。她最喜欢五颜六色的圣诞彩灯,并乐于用闪烁的色彩装饰她的阳台。为了装饰阳台,她买了一串由 $n$ 个灯组成的序列,每个灯都会发出千种颜色中的一种。

除了灯之外,小薇还非常喜欢重复的图案,因此她希望将阳台装饰成某种颜色图案连续重复 $k$ 次的样子。然而,她买的灯可能并不满足她对重复和图案的执着,所以她决定从序列的开头和结尾切掉零个或多个灯,以获得一个颜色图案连续重复 $k$ 次的序列。

请帮助她确定是否可以通过上述切割方式获得这样的灯光序列,如果可以,请打印出那个重复的图案。

输入格式

第一行包含正整数 $n$ 和 $k$ ($1 \le k \le n \le 50$),含义如上所述。 第二行包含一个正整数序列 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$),表示小薇购买的灯的颜色,按它们在序列中出现的顺序排列。

输出格式

如果小薇无法切出她想要的灯光序列,请打印 -1。 如果小薇可以切出她想要的灯光序列,请在第一行打印重复图案的长度,并在第二行打印组成该图案的颜色序列。如果存在多种解,你可以输出其中任意一个。

子任务

子任务 分值 约束
1 10 序列包含一个由单一颜色重复 $k$ 次组成的图案。
2 15 $k = 2$
3 25 无额外约束。

样例

输入 1

8 6
10 1 1 1 1 1 1 5

输出 1

1
1

输入 2

3 2
1 2 1

输出 2

-1

输入 3

10 2
1 5 1 5 2 5 6 2 5 6

输出 3

2
1 5

说明

第三个样例的说明:如果小薇从末尾切掉六个灯,从开头切掉零个灯,她会得到序列 $1\ 5\ 1\ 5$,其中图案 $1\ 5$ 连续重复了两次。另一方面,如果她从开头切掉四个灯,从末尾切掉零个灯,她会得到序列 $2\ 5\ 6\ 2\ 5\ 6$,其中图案 $2\ 5\ 6$ 重复了两次,因此这也是一个有效的解。

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.