結果
問題 | No.2956 Substitute with Average |
ユーザー |
|
提出日時 | 2025-02-25 23:10:45 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 525 ms / 3,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 3,558 ms |
コンパイル使用メモリ | 276,312 KB |
実行使用メモリ | 51,244 KB |
最終ジャッジ日時 | 2025-02-25 23:10:59 |
合計ジャッジ時間 | 13,658 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include<bits/stdc++.h>#define rep(i,n) for(int i=0;i<n;i++)using namespace std;typedef long long ll;int main(){int n;cin >> n;vector<int> a(n);for (auto &x : a) std::cin >> x;const int M = 30;const int R = n * M;long long ans = (long long)n * (n + 1) / 2;for(int x = 1; x <= M; x++){vector<int> cnt_zero(2 * R + 1);vector<int> cnt_non_zero(2 * R + 1);vector<int> b(n);rep(i, n) b[i] = a[i] - x;vector<int> s(n + 1);rep(i, n) s[i + 1] = s[i] + b[i];rep(i, n) {if(b[i] == 0){cnt_zero[R + s[i]]++;ans -= cnt_zero[R + s[i + 1]] + cnt_non_zero[R + s[i + 1]];} else {cnt_non_zero[R + s[i]]++;ans -= cnt_zero[R + s[i + 1]];}}}ans++;cout << ans << "\n";return 0;}