結果
問題 |
No.2956 Substitute with Average
|
ユーザー |
![]() |
提出日時 | 2024-11-21 12:56:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 759 bytes |
コンパイル時間 | 2,055 ms |
コンパイル使用メモリ | 191,516 KB |
最終ジャッジ日時 | 2025-02-25 05:45:23 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 3 TLE * 1 -- * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10, MAXX = 32, O = 3e6 + 1; int n, a[MAXN], sum[MAXN]; long long ans, s[2][MAXX][MAXX + O]; int main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } ans = 1ll * n * (n + 1) / 2; for(int i = 1; i <= n; i++){ ans -= s[i % 2][a[i]][O]; // cout << ans << '\n'; for(int j = 1; j <= 30; j++){ for(int k = -sum[i - 1]; k <= sum[i - 1]; k++){ s[(i + 1) % 2][j][k + (a[i] - j) + O] = s[i % 2][j][k + O]; s[i % 2][j][k + O] = 0; } } for(int j = 1; j <= 30; j++){ s[(i + 1) % 2][j][a[i] - j + O]++; } } cout << ans - n + 1; return 0; }