結果

問題 No.1765 While Shining
ユーザー yasuwoyasuwo
提出日時 2021-11-26 22:57:41
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 6,610 ms
コンパイル使用メモリ 305,812 KB
実行使用メモリ 5,648 KB
最終ジャッジ日時 2023-09-12 05:23:43
合計ジャッジ時間 7,763 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 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 12 ms
4,728 KB
testcase_10 AC 16 ms
5,116 KB
testcase_11 AC 14 ms
4,856 KB
testcase_12 AC 15 ms
5,232 KB
testcase_13 AC 14 ms
4,912 KB
testcase_14 AC 17 ms
5,400 KB
testcase_15 AC 17 ms
5,648 KB
testcase_16 AC 17 ms
5,456 KB
testcase_17 AC 18 ms
5,500 KB
testcase_18 AC 17 ms
5,512 KB
testcase_19 AC 17 ms
5,384 KB
testcase_20 AC 17 ms
5,384 KB
testcase_21 AC 17 ms
5,436 KB
testcase_22 AC 17 ms
5,448 KB
testcase_23 AC 17 ms
5,428 KB
testcase_24 AC 15 ms
5,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#include <atcoder/all>
// #include "library/templates/template.cpp"
using namespace atcoder;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

long long solve(int N, const std::vector<int> &A)
{
    vector<int> dp(N + 1, 0);
    vector<int> cnt(N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        if (A[i])
        {
            cnt[i]++;
        }
        if (i && A[i] != A[i - 1])
        {
            cnt[i] += cnt[i - 1];
            dp[i] += cnt[i - 1];
        }
        else if (i)
        {
            dp[i] += cnt[i - 1];
        }
    }
    ll res = accumulate(dp.begin(), dp.end(), 0LL);

    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int N;
    std::cin >> N;
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i)
    {
        std::cin >> A[i];
    }
    auto ans = solve(N, A);
    std::cout << ans << '\n';
    return 0;
}
0