結果

問題 No.2938 Sigma Sigma Distance Distance Problem
ユーザー ks2m
提出日時 2024-10-18 21:27:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 75,240 KB
実行使用メモリ 123,832 KB
最終ジャッジ日時 2024-10-18 22:01:04
合計ジャッジ時間 169,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 RE * 7 TLE * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ans += (j - i) * Math.abs(a[j] - a[i]);
			}
		}
		ans *= 2;
		System.out.println(ans);
	}
}
0