AT_abc473_e.K-Divisible Subarrays

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a sequence of length NN consisting of non-negative integers: A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N) .

Define the score of a sequence of length 11 or more consisting of sequences of non-negative integers, S=(S1,S2,…,Sk)S=(S _ 1,S _ 2,\ldots,S _ k), as the number of sequences Si (1≤i≤k)S _ i\ (1\le i\le k) whose sum of elements is divisible by KK.

Find the maximum possible score of a sequence of non-negative integer sequences obtained by dividing AA into one or more contiguous subsequences. Here, dividing a sequence AA of length NN into one or more contiguous subsequences means choosing a sequence of integers l=(l1,l2,…,lk) (1=l1<l2<⋯<lk≤N)l=(l _ 1,l _ 2,\ldots,l _ k)\ (1=l _ 1\lt l _ 2\lt\cdots\lt l _ k\le N) of length 11 or more, and forming the following kk sequences.

  • (Ali,Ali+1,…,Ali+1−1) (1≤i≤k)(A _ {l _ i},A _ {l _ i+1},\ldots,A _ {l _ {i+1}-1})\ (1\le i\le k) (Here, let lk+1=N+1l _ {k+1}=N+1.)

给你一个长度为 NN 的非负整数序列:A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N)。

定义一个由一个或多个非负整数序列组成的序列 S=(S1,S2,…,Sk)S=(S _ 1,S _ 2,\ldots,S _ k)(其中每个 SiS_i 长度至少为 11)的得分为:满足其元素之和能被 KK 整除的子序列 Si (1≤i≤k)S_i\ (1\le i\le k) 的个数。

求将 AA 划分为一个或多个连续子序列后,所能得到的所有非负整数序列序列的最大可能得分。这里,将长度为 NN 的序列 AA 划分为一个或多个连续子序列,是指选择一个长度至少为 11 的整数序列 l=(l1,l2,…,lk) (1=l1<l2<⋯<lk≤N)l=(l _ 1,l _ 2,\ldots,l _ k)\ (1=l _ 1\lt l _ 2\lt\cdots\lt l _ k\le N),并构造如下 kk 个序列:

  • (Ali,Ali+1,…,Ali+1−1) (1≤i≤k)(A _ {l _ i},A _ {l _ i+1},\ldots,A _ {l _ {i+1}-1})\ (1\le i\le k)(此处令 lk+1=N+1l _ {k+1}=N+1。)

输入格式

The input is given from Standard Input in the following format:

NN KK
A1A _ 1 A2A _ 2 …\ldots ANA _ N

输入从标准输入中按以下格式给出:

NN KK
A1A _ 1 A2A _ 2 …\ldots ANA _ N

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    6 10
    6 8 2 2 6 4

    输出#1

    2
  • 输入#2

    8 1
    0 0 0 0 0 0 0 0

    输出#2

    8
  • 输入#3

    30 8
    5 0 4 2 7 3 2 3 2 4 0 1 4 0 4 1 7 5 2 5 0 3 6 6 2 3 2 2 4 2

    输出#3

    8

说明/提示

Sample 1 Explanation:
For example, AA can be divided into four contiguous subsequences as (6),(8,2),(2),(6,4)(6),(8,2),(2),(6,4). The sums of the elements of the second and fourth sequences are multiples of 1010, so the score of ((6),(8,2),(2),(6,4))((6),(8,2),(2),(6,4)) is 22.

AA cannot be divided so that the score is 33 or more, so output 2.

Constraints

  • 1≤N≤2×1051\le N\le2\times10 ^ 5
  • 1≤K≤1091\le K\le10 ^ 9
  • 0≤Ai<K0\le A _ i\lt K
  • All input values are integers.

样例 1 解释:
例如,AA 可被划分为四个连续子序列:(6),(8,2),(2),(6,4)(6),(8,2),(2),(6,4)。其中第二和第四个子序列的元素之和均为 1010 的倍数,因此划分 ((6),(8,2),(2),(6,4))((6),(8,2),(2),(6,4)) 的得分为 22。

无法将 AA 划分为得分 ≥3\geq 3 的形式,故输出 2。

限制条件

  • 1≤N≤2×1051\le N\le2\times10 ^ 5
  • 1≤K≤1091\le K\le10 ^ 9
  • 0≤Ai<K0\le A _ i\lt K
  • 所有输入值均为整数。

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

首页