結果

問題 No.1505 Zero-Product Ranges
ユーザー betweens
提出日時 2021-05-20 05:39:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 545 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 68,976 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-10 07:10:00
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

template<typename H>
void print(H head) { cout << head << endl; }

int main()
{
  ll N;
  cin >> N;

  std::vector<ll> va(N);
  for (auto& a : va) cin >> a;

  ll cnt = 0LL;
  ll l = 0LL;
  ll r = 0LL;
  for (ll i = 0; i < N; i++) {
    if (va[i] == 1) {
      r = i;
    }

    if (va[i] == 0 || i == N-1) {
      ll n = r - l + 1;
      cnt += n * (n+1) / 2;
      l = i+1;
      r = i+1;
    }
  }

  ll ans = N * (N+1) / 2 - cnt;
  print(ans);
  return 0;
}
0