A8843 | Movie Critics
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A film festival is coming up in the city N. The festival will last for exactly $n$ days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to $k$ .
On the $i$ -th day the festival will show a movie of genre $a_{i}$ . We know that a movie of each of $k$ genres occurs in the festival programme at least once. In other words, each integer from 1 to $k$ occurs in the sequence $a_{1},a_{2},...,a_{n}$ at least once.
Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.
As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.
Valentine can't watch all $n$ movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the $k$ genres and will skip all the movies of this genre. He is sure to visit other movies.
Valentine wants to choose such genre $x$ ( $1<=x<=k$ ), that the total number of after-movie stresses (after all movies of genre $x$ are excluded) were minimum.
On the $i$ -th day the festival will show a movie of genre $a_{i}$ . We know that a movie of each of $k$ genres occurs in the festival programme at least once. In other words, each integer from 1 to $k$ occurs in the sequence $a_{1},a_{2},...,a_{n}$ at least once.
Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.
As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.
Valentine can't watch all $n$ movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the $k$ genres and will skip all the movies of this genre. He is sure to visit other movies.
Valentine wants to choose such genre $x$ ( $1<=x<=k$ ), that the total number of after-movie stresses (after all movies of genre $x$ are excluded) were minimum.
输入格式
The first line of the input contains two integers $n$ and $k$ ( $2<=k<=n<=10^{5}$ ), where $n$ is the number of movies and $k$ is the number of genres.
The second line of the input contains a sequence of $n$ positive integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=k$ ), where $a_{i}$ is the genre of the $i$ -th movie. It is guaranteed that each number from 1 to $k$ occurs at least once in this sequence.
The second line of the input contains a sequence of $n$ positive integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=k$ ), where $a_{i}$ is the genre of the $i$ -th movie. It is guaranteed that each number from 1 to $k$ occurs at least once in this sequence.
输出格式
Print a single number — the number of the genre (from 1 to $k$ ) of the excluded films. If there are multiple answers, print the genre with the minimum number.
输入输出样例
输入 #1
10 3 1 1 2 3 2 3 3 1 1 3
输出 #1
3
输入 #2
7 3 3 1 3 2 3 1 2
输出 #2
1
In the first sample if we exclude the movies of the 1st genre, the genres $2,3,2,3,3,3$ remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres $1,1,3,3,3,1,1,3$ remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres $1,1,2,2,1,1$ remain, that is 2 stresses.
In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted