結果
| 問題 | No.2938 Sigma Sigma Distance Distance Problem |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-18 23:06:15 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 0 ms / 2,000 ms |
| コード長 | 491 bytes |
| 記録 | |
| コンパイル時間 | 1,010 ms |
| コンパイル使用メモリ | 213,148 KB |
| 実行使用メモリ | 9,264 KB |
| 最終ジャッジ日時 | 2026-07-06 00:29:02 |
| 合計ジャッジ時間 | 2,379 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll A[555], B[555];
int main () {
int N;
cin >> N;
fill(A, A + 505, 0ll);
fill(B, B + 505, 0ll);
ll ans = 0;
for (int i = 0; i < N; i ++) {
ll a;
cin >> a;
ll p = 0, q = 0;
for (ll x = 0; x < a; x ++) {
p += A[x];
q += B[x];
ans += i * p + q;
}
p = q = 0;
for (ll x = 502; x > a; x --) {
p += A[x];
q += B[x];
ans += i * p + q;
}
A[a] ++;
B[a] -= i;
}
cout << ans * 2 << endl;
}