結果

問題 No.1505 Zero-Product Ranges
ユーザー ytqm3ytqm3
提出日時 2021-05-18 16:52:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 454 bytes
コンパイル時間 3,035 ms
コンパイル使用メモリ 195,584 KB
最終ジャッジ日時 2025-01-21 13:42:24
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;++i)
  {
    cin>>A[i];
  }
  vector<int64_t> vec;
  int x=0;
  for(int i=0;i<N;++i)
  {
    if(A[i])
    {
      x+=1;
    }
    else
    {
      vec.push_back(x);
      x=0;
    }
  }
  vec.push_back(x);
  int64_t ans=0;
  for(size_t i=0;i<vec.size();++i)
  {
    ans+=vec[i]*(vec[i]+1)/2;
  }
  cout<<N*(N+1)/2-ans<<endl;
  return 0;
}
0