結果

問題 No.1505 Zero-Product Ranges
ユーザー hatsuka_iwahatsuka_iwa
提出日時 2021-07-19 19:48:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 462 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 170,624 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-17 13:35:43
合計ジャッジ時間 5,493 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N;
  cin >> N;
  int64_t ans = 0;
  vector<int> A(N), zero_p;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (!A.at(i))
      zero_p.push_back(i);
  }

  for (int i = 0; i < N; i++) {
    if (A.at(i)) {
      auto it = lower_bound(zero_p.begin(), zero_p.end(), i);
      if (it != zero_p.end())
        ans += N - *it;
    }
    else
      ans += N - i;
  }

  cout << ans << endl;
}
0