結果
問題 |
No.2938 Sigma Sigma Distance Distance Problem
|
ユーザー |
![]() |
提出日時 | 2024-10-18 21:52:25 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 491 bytes |
コンパイル時間 | 903 ms |
コンパイル使用メモリ | 87,796 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-18 22:41:27 |
合計ジャッジ時間 | 1,899 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <cmath> #include <iostream> using namespace std; constexpr int U = 510; long long cnt0[U]; long long cnt1[U]; int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; long long ret = 0; for (int i = 0; i < N; ++i) { int a; cin >> a; for (int b = 0; b < U; ++b) { ret += abs(a - b) * (cnt0[b] * i - cnt1[b]); } cnt0[a] += 1; cnt1[a] += i; } cout << ret * 2 << '\n'; }