結果

問題 No.1505 Zero-Product Ranges
ユーザー mmn15277198
提出日時 2021-05-15 19:56:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 423 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 169,388 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-03 07:07:21
合計ジャッジ時間 3,871 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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];
  }
  long long sum = (1 + n) * n / 2;
  int now = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      now++;
    } else {
      sum -= 1LL * (now + 1) * now / 2;
      now = 0;
    }
  }
  sum -= 1LL * (now + 1) * now / 2;
  cout << sum << endl;
  return 0;
}
0