A11746 | Encryption (hard)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Heidi is now just one code away from breaking the encryption of the Death Star plans. The screen that should be presenting her with the description of the next code looks almost like the previous one, though who would have thought that the evil Empire engineers would fill this small screen with several million digits! It is just ridiculous to think that anyone would read them all...
Heidi is once again given a sequence $A$ and two integers $k$ and $p$ . She needs to find out what the encryption key $S$ is.
Let $X$ be a sequence of integers, and $p$ a positive integer. We define the score of $X$ to be the sum of the elements of $X$ modulo $p$ .
Heidi is given a sequence $A$ that consists of $N$ integers, and also given integers $k$ and $p$ . Her goal is to split $A$ into $k$ parts such that:
- Each part contains at least $1$ element of $A$ , and each part consists of contiguous elements of $A$ .
- No two parts overlap.
- The total sum $S$ of the scores of those parts is minimized (not maximized!).
Output the sum $S$ , which is the encryption code.
Heidi is once again given a sequence $A$ and two integers $k$ and $p$ . She needs to find out what the encryption key $S$ is.
Let $X$ be a sequence of integers, and $p$ a positive integer. We define the score of $X$ to be the sum of the elements of $X$ modulo $p$ .
Heidi is given a sequence $A$ that consists of $N$ integers, and also given integers $k$ and $p$ . Her goal is to split $A$ into $k$ parts such that:
- Each part contains at least $1$ element of $A$ , and each part consists of contiguous elements of $A$ .
- No two parts overlap.
- The total sum $S$ of the scores of those parts is minimized (not maximized!).
Output the sum $S$ , which is the encryption code.
输入格式
The first line of the input contains three space-separated integers $N$ , $k$ and $p$ ( $k<=N<=500000$ , $2<=k<=100$ , $2<=p<=100$ ) – the number of elements in $A$ , the number of parts $A$ should be split into, and the modulo for computing scores, respectively.
The second line contains $N$ space-separated integers that are the elements of $A$ . Each integer is from the interval $[1,1000000]$ .
The second line contains $N$ space-separated integers that are the elements of $A$ . Each integer is from the interval $[1,1000000]$ .
输出格式
Output the number $S$ as described in the problem statement.
输入输出样例
输入 #1
4 3 10 3 4 7 2
输出 #1
6
输入 #2
10 5 12 16 3 24 13 9 8 7 5 12 12
输出 #2
13
In the first example, if the input sequence is split as $(3)$ , $(4,7)$ , $(2)$ , the total score would be . It is easy to see that this score is the smallest possible.
In the second example, one possible way to obtain score $13$ is to make the following split: $(16,3)$ , $(24)$ , $(13)$ , $(9,8)$ , $(7,5,12,12)$ .
In the second example, one possible way to obtain score $13$ is to make the following split: $(16,3)$ , $(24)$ , $(13)$ , $(9,8)$ , $(7,5,12,12)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted