AT_abc473_e.K-Divisible Subarrays
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence of length N consisting of non-negative integers: A=(A1,A2,…,AN) .
Define the score of a sequence of length 1 or more consisting of sequences of non-negative integers, S=(S1,S2,…,Sk), as the number of sequences Si (1≤i≤k) whose sum of elements is divisible by K.
Find the maximum possible score of a sequence of non-negative integer sequences obtained by dividing A into one or more contiguous subsequences. Here, dividing a sequence A of length N into one or more contiguous subsequences means choosing a sequence of integers l=(l1,l2,…,lk) (1=l1<l2<⋯<lk≤N) of length 1 or more, and forming the following k sequences.
- (Ali,Ali+1,…,Ali+1−1) (1≤i≤k) (Here, let lk+1=N+1.)
给你一个长度为 N 的非负整数序列:A=(A1,A2,…,AN)。
定义一个由一个或多个非负整数序列组成的序列 S=(S1,S2,…,Sk)(其中每个 Si 长度至少为 1)的得分为:满足其元素之和能被 K 整除的子序列 Si (1≤i≤k) 的个数。
求将 A 划分为一个或多个连续子序列后,所能得到的所有非负整数序列序列的最大可能得分。这里,将长度为 N 的序列 A 划分为一个或多个连续子序列,是指选择一个长度至少为 1 的整数序列 l=(l1,l2,…,lk) (1=l1<l2<⋯<lk≤N),并构造如下 k 个序列:
- (Ali,Ali+1,…,Ali+1−1) (1≤i≤k)(此处令 lk+1=N+1。)
输入格式
The input is given from Standard Input in the following format:
N K
A1 A2 … AN
输入从标准输入中按以下格式给出:
N K
A1 A2 … AN
输出格式
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, A can be divided into four contiguous subsequences as (6),(8,2),(2),(6,4). The sums of the elements of the second and fourth sequences are multiples of 10, so the score of ((6),(8,2),(2),(6,4)) is 2.
A cannot be divided so that the score is 3 or more, so output 2.
Constraints
- 1≤N≤2×105
- 1≤K≤109
- 0≤Ai<K
- All input values are integers.
样例 1 解释:
例如,A 可被划分为四个连续子序列:(6),(8,2),(2),(6,4)。其中第二和第四个子序列的元素之和均为 10 的倍数,因此划分 ((6),(8,2),(2),(6,4)) 的得分为 2。
无法将 A 划分为得分 ≥3 的形式,故输出 2。
限制条件
- 1≤N≤2×105
- 1≤K≤109
- 0≤Ai<K
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?