AT_ndpc2026_k.Addition and Subtraction

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given an integer sequence A=(A1,A2,…,AN)A = (A_1, A_2, \dots, A_N) of length NN.
You also have an integer xx, which is initially 00.

You will perform the following NN operations:

  • For i=1,2,…,Ni = 1, 2, \dots, N, choose exactly one of the following three operations:
    • Replace xx with x+Aix + A_i.
    • Replace xx with ∣x−Ai∣\vert x - A_i \vert.
    • Do nothing.

Find the number of possible values of xx after all NN operations are completed.

给你一个长度为 NN 的整数序列 A=(A1,A2,…,AN)A = (A_1, A_2, \dots, A_N)。
你还拥有一个整数 xx,其初始值为 00。

你将执行以下 NN 次操作:

  • 对于 i=1,2,…,Ni = 1, 2, \dots, N,从以下三种操作中恰好选择一种:
    • 将 xx 替换为 x+Aix + A_i;
    • 将 xx 替换为 ∣x−Ai∣\vert x - A_i \vert;
    • 不进行任何操作。

求所有 NN 次操作完成后,xx 可能取到的不同值的个数。

输入格式

The input is given from standard input in the following format:

NN
A1A_1 A2A_2 …\dots ANA_N

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

NN
A1A_1 A2A_2 …\dots ANA_N

输出格式

Print the number of possible values of xx after all NN operations are completed.

输出完成所有 NN 次操作后 xx 的可能取值个数。

输入输出样例

  • 输入#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=1NAi≤5×105\displaystyle 1 \leq \sum_{i=1}^N A_i \leq 5 \times 10^5, you will get 44 points.

Sample 1 Explanation:
For example, you can obtain x=9x = 9 by performing the following operations:

  • Initially, x=0x = 0.
  • At i=1i = 1, replace xx with ∣x−Ai∣=∣0−2∣=2\vert x - A_i \vert = \vert 0 - 2 \vert = 2.
  • At i=2i = 2, replace xx with x+Ai=2+7=9x + A_i = 2 + 7 = 9.
  • At i=3i = 3, do nothing.

Constraints

  • 1≤N≤5×1051 \leq N \leq 5 \times 10^5
  • 1≤Ai≤2×1061 \leq A_i \leq 2 \times 10^6
  • 1≤∑i=1NAi≤2×106\displaystyle 1 \leq \sum_{i=1}^N A_i \leq 2 \times 10^6
  • All input values are integers

部分得分

本题采用部分得分制。

  • 若你解决了满足 1≤∑i=1NAi≤5×105\displaystyle 1 \leq \sum_{i=1}^N A_i \leq 5 \times 10^5 的数据集,则可获得 44 分。

样例 1 解释:
例如,可通过以下操作得到 x=9x = 9:

  • 初始时,x=0x = 0。
  • 当 i=1i = 1 时,将 xx 替换为 ∣x−Ai∣=∣0−2∣=2\vert x - A_i \vert = \vert 0 - 2 \vert = 2。
  • 当 i=2i = 2 时,将 xx 替换为 x+Ai=2+7=9x + A_i = 2 + 7 = 9。
  • 当 i=3i = 3 时,不进行任何操作。

约束条件

  • 1≤N≤5×1051 \leq N \leq 5 \times 10^5
  • 1≤Ai≤2×1061 \leq A_i \leq 2 \times 10^6
  • 1≤∑i=1NAi≤2×106\displaystyle 1 \leq \sum_{i=1}^N A_i \leq 2 \times 10^6
  • 所有输入值均为整数

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

首页