結果

問題 No.2956 Substitute with Average
ユーザー はーチャンネル
提出日時 2024-12-12 11:03:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 3,681 ms
コンパイル使用メモリ 277,012 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-12 11:03:41
合計ジャッジ時間 5,475 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<VL> VVL;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
  int n;cin>>n;
  int AA[n];
  rep(i,n){cin>>AA[i];}
  LL ans=LL(n)*(n+1)/2;
  //cout<<ans<<endl;
  for(int i=1;i<=30;i++){
    //cout<<i<<endl;
    VI A,B;
    int a=0,b=0,sum=0;
    rep(j,n){
      //cout<<A[j]<<endl;
      if(AA[j]==i){
        if(sum!=0){
          if(b==sum*i){B.pb(1);}
          else{B.pb(0);}
          b=0;sum=0;
        }
        a++;
      }
      else{
        if(a!=0){
          A.pb(a);a=0;
        }
        b+=AA[j];sum++;
      }
      //cout<<b<<endl;
    }
    if(a!=0){A.pb(a);}
    int m=A.size();
    //cout<<m<<' '<<B.size()<<endl;
    rep(i,m){
      //cout<<A[i]<<endl;
      ans-=LL(A[i])*(A[i]+1)/2;}
    rep(i,m-1){
      if(B[i]){ans-=LL(A[i]+1)*(A[i+1]+1)-1;}
    }
    //cout<<15-ans<<endl;
  }
  ans++;
  cout<<ans<<endl;
}
0