結果

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

ソースコード

diff #

#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

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

template<typename H, typename... T>
void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}


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

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

  ll cnt = 0LL;
  ll ans = 0LL;
  for (ll i = 0; i < N; i++) {
    if (va[i] == 0) {
      ans += cnt * (cnt + 1) / 2;
      cnt = 0;
    } else {
      cnt++;
    }
  }
  ans += cnt * (cnt + 1) / 2;

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