結果
問題 | No.2938 Sigma Sigma Distance Distance Problem |
ユーザー |
|
提出日時 | 2024-10-18 21:32:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 754 bytes |
コンパイル時間 | 3,028 ms |
コンパイル使用メモリ | 249,900 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-10-18 22:17:12 |
合計ジャッジ時間 | 7,387 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; #ifdef DEFINED_ONLY_IN_LOCAL #include <dump.hpp> #define dump(...) cpp_dump(__VA_ARGS__) #else #undef dump #define dump(...) #endif #define rep(i, n) for (int i = 0; i < n; i++) template <class T> istream& operator>>(istream& I, vector<T>& V) { for (T& X : V) I >> X; return I; } int main() { int n; cin >> n; vector<int> a(n), cnt(500); vector<long> s(500); cin >> a; rep(i, n) a[i]--; long ans = 0; rep(i, n) { rep(j, 500) { int x = abs(a[i] - j); ans += x * ((long)cnt[j] * i - s[j]) * 2; } cnt[a[i]]++; s[a[i]] += i; } cout << ans << endl; return 0; }