AT_ndpc2026_k.Addition and Subtraction
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer sequence A=(A1,A2,…,AN) of length N.
You also have an integer x, which is initially 0.
You will perform the following N operations:
- For i=1,2,…,N, choose exactly one of the following three operations:
- Replace x with x+Ai.
- Replace x with ∣x−Ai∣.
- Do nothing.
Find the number of possible values of x after all N operations are completed.
给你一个长度为 N 的整数序列 A=(A1,A2,…,AN)。
你还拥有一个整数 x,其初始值为 0。
你将执行以下 N 次操作:
- 对于 i=1,2,…,N,从以下三种操作中恰好选择一种:
- 将 x 替换为 x+Ai;
- 将 x 替换为 ∣x−Ai∣;
- 不进行任何操作。
求所有 N 次操作完成后,x 可能取到的不同值的个数。
输入格式
The input is given from standard input in the following format:
N
A1 A2 … AN
输入从标准输入中按以下格式给出:
N
A1 A2 … AN
输出格式
Print the number of possible values of x after all N operations are completed.
输出完成所有 N 次操作后 x 的可能取值个数。
输入输出样例
输入#1
3 2 7 5
输出#1
10
输入#2
10 49 85 36 30 71 65 38 45 73 27
输出#2
454
说明/提示
Partial Score
This problem has partial scoring.
- If you solve the dataset with 1≤i=1∑NAi≤5×105, you will get 4 points.
Sample 1 Explanation:
For example, you can obtain x=9 by performing the following operations:
- Initially, x=0.
- At i=1, replace x with ∣x−Ai∣=∣0−2∣=2.
- At i=2, replace x with x+Ai=2+7=9.
- At i=3, do nothing.
Constraints
- 1≤N≤5×105
- 1≤Ai≤2×106
- 1≤i=1∑NAi≤2×106
- All input values are integers
部分得分
本题采用部分得分制。
- 若你解决了满足 1≤i=1∑NAi≤5×105 的数据集,则可获得 4 分。
样例 1 解释:
例如,可通过以下操作得到 x=9:
- 初始时,x=0。
- 当 i=1 时,将 x 替换为 ∣x−Ai∣=∣0−2∣=2。
- 当 i=2 时,将 x 替换为 x+Ai=2+7=9。
- 当 i=3 时,不进行任何操作。
约束条件
- 1≤N≤5×105
- 1≤Ai≤2×106
- 1≤i=1∑NAi≤2×106
- 所有输入值均为整数
输入解题思路,AI测评打分。不知道怎么写?