CF958C3.Encryption (hard)

省选/NOI-

通过率:0%

时间限制:2.20s

内存限制:512MB

AC君温馨提醒

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

题目描述

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.

海蒂距离破解死星设计图的加密仅剩最后一段代码了。本该向她展示下一段密码描述的屏幕,看起来与之前的屏幕几乎一样,然而谁能想到邪恶帝国的工程师竟在这块小小的屏幕上填满了数百万个数字!简直难以想象会有人把它们全部读完……

海蒂再次获得一个序列 AA 以及两个整数 kk 和 pp。她需要找出加密密钥 SS。

设 XX 是一个整数序列,pp 为一个正整数。我们定义 XX 的得分为 XX 中所有元素之和对 pp 取模的结果。

海蒂获得一个由 NN 个整数组成的序列 AA,以及整数 kk 和 pp。她的目标是将 AA 划分为 kk 个部分,使得:

  • 每一部分至少包含 AA 中的一个元素,且每一部分均由 AA 中连续的元素构成;
  • 任意两部分互不重叠;
  • 这些部分的得分之和 SS 最小化(注意:不是最大化!)。

输出该和 SS,即为加密代码。

输入格式

The first line of the input contains three space-separated integers N, k and p (k ≤ N ≤ 500 000, 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, 1 000 000].

输入的第一行包含三个以空格分隔的整数 NN、kk 和 pp(满足 k≤N≤500 000k \leq N \leq 500\,000,2≤k≤1002 \leq k \leq 100,2≤p≤1002 \leq p \leq 100),分别表示数组 AA 的元素个数、将 AA 划分为的段数,以及计算得分时所用的模数。

第二行包含 NN 个以空格分隔的整数,即数组 AA 的元素。每个整数均在区间 [1, 1 000 000][1,\,1\,000\,000] 内。

输出格式

Output the number S as described in the problem statement.

输出问题描述中所述的数 S。

输入输出样例

  • 输入#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).

在第一个例子中,如果输入序列被划分为 (3)、(4, 7)、(2),则总得分为 。显然,该得分是最小可能值。

在第二个例子中,一种可得到得分 13 的划分方式为:(16, 3)、(24)、(13)、(9, 8)、(7, 5, 12, 12)。

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

首页