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 n passenger seats, seat i can be occupied only by a participant from the city ai.
Today, the bus has completed m trips, each time bringing n 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,…,an repeated m times).
After that some teams were formed, each consisting of k 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 k 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)在一座偏远城市举行,而该城市仅能通过一辆小型巴士抵达。这辆巴士共有 n 个乘客座位,其中第 i 号座位只能由来自城市 ai 的参赛者乘坐。
今天,该巴士共完成了 m 趟运输,每趟运送 n 名参赛者。随后,所有参赛者按到达顺序排成一列;同一趟巴士上的参赛者,在队列中按其座位编号顺序排列(即:若将每位参赛者所来自的城市依次写出,则得到序列 a1,a2,…,an 重复 m 次)。
之后,开始组队:每支队伍由恰好 k 名来自同一城市的参赛者组成,且他们在队列中必须彼此相邻。一旦组队完成,该队伍即离开队列。该过程持续进行,直到队列中不再存在 k 个相邻的、来自同一城市的参赛者为止。
请帮助组织者计算:当该过程结束时,队列中还剩下多少名参赛者?我们可以证明,最终剩余人数与每次组队所选择的具体位置顺序无关。
输入格式
The first line contains three integers n,k and m (1≤n≤105, 2≤k≤109, 1≤m≤109).
The second line contains n integers a1,a2,…,an (1≤ai≤105), where ai is the index of city where the person occupying the i-th seat in the bus must be from.
第一行包含三个整数 n,k 和 m(1≤n≤105,2≤k≤109,1≤m≤109)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤105),其中 ai 表示坐在公交车第 i 个座位上的人所来自的城市编号。
输出格式
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测评打分。不知道怎么写?