問題一覧 > 通常問題

No.2938 Sigma Sigma Distance Distance Problem

レベル : / AI推定難易度 : 115 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 179
作問者 : kazuppa / テスター : yuusaan kakao745 hirayuu_yc
お気に入りにしたユーザー ProblemId : 11350 / 自分の提出
問題文最終更新日: 2024-10-18 21:43:18
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 450 (順位表) の他の問題:

Problem Statement

You are given an integer sequence $A_1,A_2,\ ...\ , A_{N}$ of length $N$. $\\$ Find $\left(\displaystyle\sum_{i=1}^{N}\displaystyle\sum_{j=1}^{N} \ \left|i-j\right| \times \left|A_i-A_j\right|\right)$.

Input

The input is given from standard input in the following format.
$N$
$A_1\ \ A_2\ ... \ A_{N}$

Constraints

  • $1\leq N\leq 100$
  • $1\leq A_i\leq 100(1\leq i\leq N)\\$
  • All inputs are integers.
This problem also has evil cases, which do not affect the AC verdict. If you have the energy to spare, feel free to try them.

Constraints for the evil cases
  • $1\leq N\leq 2\times 10^5$
  • $1\leq A_i\leq 500(1\leq i\leq N)$
  • All inputs are integers.
If you are not attempting the evil cases, having your program terminate immediately when the input does not satisfy the normal constraints will make the judging finish sooner.

Output

Print $\left(\displaystyle\sum_{i=1}^{N}\displaystyle\sum_{j=1}^{N} \ \left|i-j\right| \times \left|A_i-A_j\right|\right)$ on one line, followed by a newline.

Sample

Sample 1
Input
2
3 2
Output
2

The value of $(|i-j| \times |A_i-A_j|)$ for each $(i,j)$ is as follows.

  • $(1,1)=|1-1|\times |A_1-A_1|=0$
  • $(1,2)=|1-2|\times |A_1-A_2|=1$
  • $(2,1)=|2-1|\times |A_2-A_1|=1$
  • $(2,2)=|2-2|\times |A_2-A_2|=0$
  • Therefore, the answer is $0+1+1+0=2$.

    Sample 2
    Input
    3
    1 2 3
    
    Output
    12

    Sample 3
    Input
    9
    41 15 76 69 70 58 10 20 34
    
    Output
    7196

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。