結果

問題 No.2938 Sigma Sigma Distance Distance Problem
ユーザー kazuppa
提出日時 2024-10-15 22:02:33
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 462 bytes
コンパイル時間 3,539 ms
コンパイル使用メモリ 274,804 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 22:22:32
合計ジャッジ時間 7,285 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  ll n, m = 500;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++)
    cin >> a[i];
  vector<ll> t(m + 1), u(m + 1);
  for(int i = 0; i < n; i++) {
    t[a[i]] += i;
    u[a[i]]++;
  }
  ll ans = 0;
  for(ll k = 0; k < n; k++) {
    t[a[k]] -= k;
    u[a[k]]--;
    for(ll i = 1; i <= m; i++)
      ans += (t[i] - k * u[i]) * abs(a[k] - i);
  }
  cout << ans * 2 << endl;
}
0