CF878B.Teams Formation

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This time, the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. The bus has nn passenger seats, seat ii can be occupied only by a participant from the city aia_i.

Today, the bus has completed mm trips, each time bringing nn participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1,a2,…,ana_1, a_2, \ldots, a_n repeated mm times).

After that some teams were formed, each consisting of kk participants from the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no kk neighboring participants from the same city.

Help the organizers determine how many participants are left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.

这一次,贝尔兰信息学奥林匹克竞赛(Berland Team Olympiad in Informatics)在一座偏远城市举行,而该城市仅能通过一辆小型巴士抵达。这辆巴士共有 nn 个乘客座位,其中第 ii 号座位只能由来自城市 aia_i 的参赛者乘坐。

今天,该巴士共完成了 mm 趟运输,每趟运送 nn 名参赛者。随后,所有参赛者按到达顺序排成一列;同一趟巴士上的参赛者,在队列中按其座位编号顺序排列(即:若将每位参赛者所来自的城市依次写出,则得到序列 a1,a2,…,ana_1, a_2, \ldots, a_n 重复 mm 次)。

之后,开始组队:每支队伍由恰好 kk 名来自同一城市的参赛者组成,且他们在队列中必须彼此相邻。一旦组队完成,该队伍即离开队列。该过程持续进行,直到队列中不再存在 kk 个相邻的、来自同一城市的参赛者为止。

请帮助组织者计算:当该过程结束时,队列中还剩下多少名参赛者?我们可以证明,最终剩余人数与每次组队所选择的具体位置顺序无关。

输入格式

The first line contains three integers n,kn, k and mm (1≤n≤1051 \le n \le 10^5, 2≤k≤1092 \le k \le 10^9, 1≤m≤1091 \le m \le 10^9).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1051 \le a_i \le 10^5), where aia_i is the index of city where the person occupying the ii-th seat in the bus must be from.

第一行包含三个整数 n,kn, k 和 mm(1≤n≤1051 \le n \le 10^5,2≤k≤1092 \le k \le 10^9,1≤m≤1091 \le m \le 10^9)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1051 \le a_i \le 10^5),其中 aia_i 表示坐在公交车第 ii 个座位上的人所来自的城市编号。

输出格式

Output the number of remaining participants in the line.

输出队伍中剩余参与者的数量。

输入输出样例

  • 输入#1

    4 2 5
    1 2 3 1

    输出#1

    12
  • 输入#2

    1 9 10
    1

    输出#2

    1
  • 输入#3

    3 2 10
    1 2 1

    输出#3

    0

说明/提示

In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.

在第二个例子中,队伍由来自同一城市的十名参与者组成。其中九人将组成一支队伍。最终,队伍中仅剩一名参与者。

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

首页