結果

問題 No.2956 Substitute with Average
ユーザー ripityripity
提出日時 2024-11-08 22:53:02
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,523 ms / 3,000 ms
コード長 599 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 209,908 KB
実行使用メモリ 13,552 KB
最終ジャッジ日時 2024-11-08 22:53:27
合計ジャッジ時間 22,942 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for(int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  constexpr int M = 30;
  long long ans = (long long) N * (N + 1) / 2;
  for(int x = 1; x <= M; x++) {
    vector<int> B = A;
    for(int i = 1; i <= N; i++) {
      B[i] += B[i - 1] - x;
    }
    map<int, int> mp, mp2;
    for(int i = 0; i <= N; i++) {
      if(A[i] == x) {
        ans -= mp[B[i]] + mp2[B[i]];
        mp2[B[i]]++;
      }else {
        ans -= mp2[B[i]];
        mp[B[i]]++;
      }
    }
  }
  cout << ans + 1 << endl;
}
0