結果
問題 | No.1505 Zero-Product Ranges |
ユーザー |
![]() |
提出日時 | 2021-05-30 03:40:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 475 bytes |
コンパイル時間 | 1,582 ms |
コンパイル使用メモリ | 168,344 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 20:37:52 |
合計ジャッジ時間 | 4,067 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <bits/stdc++.h>#define NIL (-1)#define ll long longusing namespace std;const int64_t MOD = 1e9 + 7;const int INF = INT_MAX;const double PI = acos(-1.0);int main() {ll N;cin >> N;vector<ll> A(N);for (int i = 0; i < N; i++) cin >> A[i];ll ones = 0;ll cnt = 0;for (int i = 0; i < N; i++) {if (A[i]) cnt++;if (A[i] == 0 || i == N - 1) {ones += cnt*(cnt+1)/2;cnt = 0;}}ll ans = N * (N + 1) / 2 - ones;cout << ans << endl;}