CF1163B1.Cat Party (Easy Edition)
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This problem is same as the next one, but has smaller constraints.
Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time.
For each of the n days since the day Shiro moved to the new house, there will be exactly one cat coming to the Shiro's house. The cat coming in the i-th day has a ribbon with color ui. Shiro wants to know the largest number x, such that if we consider the streak of the first x days, it is possible to remove exactly one day from this streak so that every ribbon color that has appeared among the remaining x−1 will have the same number of occurrences.
For example, consider the following sequence of ui: [2,2,1,1,5,4,4,5]. Then x=7 makes a streak, since if we remove the leftmost ui=5, each ribbon color will appear exactly twice in the prefix of x−1 days. Note that x=8 doesn't form a streak, since you must remove exactly one day.
Since Shiro is just a cat, she is not very good at counting and needs your help finding the longest streak.
本题与下一题相同,但约束条件更小。
Shiro 刚刚搬进新家。她想邀请自己所有的朋友来家里玩大富翁游戏。然而,她的房子太小了,每次只能邀请一位朋友。
在 Shiro 搬入新家后的 n 天中,每天恰好有一只猫来到她家。第 i 天到来的猫佩戴着颜色为 ui 的丝带。Shiro 想知道最大的整数 x,使得:若考虑前 x 天构成的连续区间,则存在恰好去掉其中一天的方法,使得剩余 x−1 天中,每种出现过的丝带颜色的出现次数均相等。
例如,考虑如下 ui 序列:[2,2,1,1,5,4,4,5]。此时 x=7 构成一个合法区间,因为若去掉最左侧的 ui=5(即第 5 天),则前 x−1=6 天的前缀中,每种出现的颜色(1,2,4)均恰好出现两次。注意 x=8 不构成合法区间,因为必须恰好去掉一天。
由于 Shiro 只是一只猫,不擅长计数,因此需要你帮助她找出最长的合法区间。
输入格式
The first line contains a single integer n (1≤n≤105) — the total number of days.
The second line contains n integers u1,u2,…,un (1≤ui≤10) — the colors of the ribbons the cats wear.
第一行包含一个整数 n(1≤n≤105)—— 总天数。
第二行包含 n 个整数 u1,u2,…,un(1≤ui≤10)—— 猫咪所佩戴丝带的颜色。
输出格式
Print a single integer x — the largest possible streak of days.
输出一个整数 x —— 最长可能的连续天数。
输入输出样例
输入#1
13 1 1 1 2 2 2 3 3 3 4 4 4 5
输出#1
13
输入#2
5 10 2 5 4 1
输出#2
5
输入#3
1 10
输出#3
1
输入#4
7 3 2 1 1 4 5 1
输出#4
6
输入#5
6 1 1 1 2 2 2
输出#5
5
说明/提示
In the first example, we can choose the longest streak of 13 days, since upon removing the last day out of the streak, all of the remaining colors 1, 2, 3, and 4 will have the same number of occurrences of 3. Note that the streak can also be 10 days (by removing the 10-th day from this streak) but we are interested in the longest streak.
In the fourth example, if we take the streak of the first 6 days, we can remove the third day from this streak then all of the remaining colors 1, 2, 3, 4 and 5 will occur exactly once.
在第一个例子中,我们可以选择最长的连续 13 天,因为从此连续区间中移除最后一天后,其余所有颜色 1、2、3 和 4 的出现次数均为 3。注意,该连续区间也可以是 10 天(即从此连续区间中移除第 10 天),但我们关注的是最长的连续区间。
在第四个例子中,若取前 6 天构成的连续区间,则从此连续区间中移除第 3 天后,其余所有颜色 1、2、3、4 和 5 均恰好出现一次。
输入解题思路,AI测评打分。不知道怎么写?