結果

問題 No.2956 Substitute with Average
ユーザー テナガザル
提出日時 2024-11-08 23:17:58
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 640 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 115,048 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-11-08 23:18:05
合計ジャッジ時間 5,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<map<int, int>> mp(30);
  vector<int> sum(n + 1);
  for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] + a[i];
  mp[a[0] - 1][0] = 1;
  long long ans = (long long)(n + 1) * n / 2 + 1;
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 0; j < 30; ++j)
    {
      int tmp = sum[i] - (j + 1) * i;
      if (mp[j].find(tmp) != mp[j].end()) ans -= mp[j][tmp];
    }
    if (i < n) mp[a[i] - 1][sum[i] - i * a[i]]++;
  }
  cout << ans << endl;
}
0