結果

問題 No.1505 Zero-Product Ranges
ユーザー Ichimiya
提出日時 2021-05-30 03:39:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 478 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 167,616 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 20:37:47
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define NIL (-1)
#define ll long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;
const double PI = acos(-1.0);

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

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	ll ones = 0;
	int 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;
}
0