結果

問題 No.1505 Zero-Product Ranges
ユーザー icchipost
提出日時 2021-05-15 09:33:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 165,508 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 16:04:03
合計ジャッジ時間 4,305 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  ll ans = (ll)n * (n + 1) / 2;
  int cnt = 0;
  rep(i, n) {
    int a;
    cin >> a;
    if (a == 1) cnt++;
    else {
      ans -= (ll)cnt * (cnt + 1) / 2;
      cnt = 0;
    }
  }
  if (cnt) ans -= (ll)cnt * (cnt + 1) / 2;
  cout << ans << endl;
  return 0;
}
0