結果
問題 | No.1505 Zero-Product Ranges |
ユーザー |
![]() |
提出日時 | 2021-05-14 22:50:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 462 bytes |
コンパイル時間 | 561 ms |
コンパイル使用メモリ | 63,752 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 03:15:43 |
合計ジャッジ時間 | 2,516 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <iostream> #define int long long using namespace std; int n; int a[200000]; signed main() { int i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; int non_zero_seg_cnt = 0; int len = 0; for (i = 0; i < n; i++) { if (a[i] == 0) { non_zero_seg_cnt += len * (len + 1) / 2; len = 0; } else { len++; } } non_zero_seg_cnt += len * (len + 1) / 2; int ans = n * (n + 1) / 2 - non_zero_seg_cnt; cout << ans << endl; return 0; }