結果
問題 | No.2938 Sigma Sigma Distance Distance Problem |
ユーザー |
![]() |
提出日時 | 2024-10-15 22:01:28 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 462 bytes |
コンパイル時間 | 4,417 ms |
コンパイル使用メモリ | 274,892 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 22:22:21 |
合計ジャッジ時間 | 8,001 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#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;}