結果
| 問題 |
No.2938 Sigma Sigma Distance Distance Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-08 23:20:25 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,029 bytes |
| コンパイル時間 | 1,865 ms |
| コンパイル使用メモリ | 32,128 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 23:20:29 |
| 合計ジャッジ時間 | 2,869 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
!> This file was processed by `fypp`.
!> Today's fortune: "Lucky:)", really OK?
!> ランダムウォーク猿「'bit DP' で はっぴー.」
!> ギャンブラー猿「AtCoder はゲームだ.」
program f902938
use, intrinsic :: iso_fortran_env
!> auto use module
implicit none
integer(int32), parameter :: max_a = 500
integer(int32) :: n
integer(int32), allocatable :: arr(:)
integer(int64) :: idx_sums(max_a), cnts(max_a)
integer(int64) :: ans
integer(int32) :: i, v
read(input_unit, *) n
allocate(arr(n))
read(input_unit, *) arr(:)
idx_sums(:) = 0_int64
cnts(:) = 0_int64
ans = 0_int64
!> 2 * Σ_{i = 1}^{n}Σ_{j = i + 1}^{n}(...) == Σ_{i = 1}^{n}Σ_{j = 1}^{n}(...)
do i = 1, n
associate(idx => n - i)
do v = 1, max_a
ans = ans + (idx_sums(v) - cnts(v) * idx) * abs(v - arr(i))
end do
idx_sums(arr(i)) = idx_sums(arr(i)) + idx
cnts(arr(i)) = cnts(arr(i)) + 1
end associate
end do
write(output_unit, '(i0)') 2 * ans
end program f902938