結果
問題 | No.1765 While Shining |
ユーザー |
|
提出日時 | 2021-10-21 19:44:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 519 bytes |
コンパイル時間 | 2,489 ms |
コンパイル使用メモリ | 195,704 KB |
最終ジャッジ日時 | 2025-01-25 02:30:34 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#define rep(i,n) for(int i=0;i<n;++i)int main() {int n; cin >> n;vector<int> a(n);rep(i,n)cin >> a[i];auto b = a;for (int i = 1; i < n; i += 2)b[i] ^= 1;b.push_back(-1);int pre = n;vector<int> c(n);for(int i = n - 1; 0 <= i; --i) {if (b[i] != b[pre])pre = i;c[i] = pre + 1;}ll ans = 0;rep(i,n)if (a[i])ans += min(c[i], n - 1) - i;cout << ans << "\n";return 0;}