結果

問題 No.1765 While Shining
ユーザー first_vilfirst_vil
提出日時 2021-10-21 19:44:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 201,272 KB
実行使用メモリ 5,540 KB
最終ジャッジ日時 2023-09-12 04:43:54
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,504 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 21 ms
4,560 KB
testcase_10 AC 31 ms
5,104 KB
testcase_11 AC 27 ms
4,872 KB
testcase_12 AC 30 ms
5,068 KB
testcase_13 AC 27 ms
5,012 KB
testcase_14 AC 33 ms
5,508 KB
testcase_15 AC 34 ms
5,488 KB
testcase_16 AC 33 ms
5,444 KB
testcase_17 AC 33 ms
5,384 KB
testcase_18 AC 33 ms
5,440 KB
testcase_19 AC 33 ms
5,348 KB
testcase_20 AC 33 ms
5,488 KB
testcase_21 AC 33 ms
5,404 KB
testcase_22 AC 33 ms
5,384 KB
testcase_23 AC 34 ms
5,540 KB
testcase_24 AC 33 ms
5,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0