結果

問題 No.1505 Zero-Product Ranges
ユーザー Mr.Spock
提出日時 2021-05-16 21:59:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 1,443 ms
コンパイル使用メモリ 168,032 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-05 08:50:47
合計ジャッジ時間 3,873 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll get(ll n) {
	return (n * (n + 1)) / 2;
}
void solve() {
	ll n;
	cin >> n;
	vector<ll>x(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	ll cnt = 0;
	ll ans = get(n);
	for (ll i = 0; i < n; i++) {
		if (x[i] == 1)cnt++;
		else {
			ans -= get(cnt);
			cnt = 0;
		}
	}
	ans -= get(cnt);
	cout << ans << endl;
}
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll test = 1;
	while (test--) {
		solve();
	}
}
0