結果

問題 No.2938 Sigma Sigma Distance Distance Problem
ユーザー Xinyuan Huang
提出日時 2025-02-21 17:07:55
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 3,471 ms
コンパイル使用メモリ 276,528 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-21 17:08:00
合計ジャッジ時間 4,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

constexpr int M = 500;

int main() {
    int n; std::cin >> n;
    i64 res = 0;
    std::vector<i64> cnt(M + 1), sum(M + 1);
    for (int i = 1; i <= n; ++i) {
        int x; std::cin >> x;
        for (int y = 1; y < x; ++y)
            res += (i * cnt[y] - sum[y]) * (x - y);
        for (int y = x + 1; y <= M; ++y)
            res += (i * cnt[y] - sum[y]) * (y - x);
        cnt[x] += 1;
        sum[x] += i;
    }
    std::cout << res * 2 << "\n";
    return 0;
}
0