結果

問題 No.1765 While Shining
ユーザー se1ka2se1ka2
提出日時 2021-11-26 22:28:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 64,128 KB
実行使用メモリ 5,936 KB
最終ジャッジ日時 2023-09-12 05:09:19
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
5,372 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 21 ms
4,836 KB
testcase_10 AC 30 ms
5,584 KB
testcase_11 AC 26 ms
5,524 KB
testcase_12 AC 29 ms
5,408 KB
testcase_13 AC 27 ms
5,240 KB
testcase_14 AC 32 ms
5,660 KB
testcase_15 AC 33 ms
5,752 KB
testcase_16 AC 32 ms
5,728 KB
testcase_17 AC 32 ms
5,936 KB
testcase_18 AC 33 ms
5,664 KB
testcase_19 AC 32 ms
5,692 KB
testcase_20 AC 32 ms
5,932 KB
testcase_21 AC 32 ms
5,664 KB
testcase_22 AC 32 ms
5,840 KB
testcase_23 AC 33 ms
5,692 KB
testcase_24 AC 31 ms
5,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[200005];
    for(int i = 0; i < n; i++) cin >> a[i];
    a[n] = 0;
    ll s[200005];
    s[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--){
        if(a[i] == 0) s[i] = 0;
        if(a[i] == 1){
            if(i < n - 2 && a[i + 1] == 0){
                if(a[i + 2] == 1) s[i] = s[i + 2] + 2;
                else s[i] = 2;
            }
            else s[i] = 1;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) ans += s[i];
    cout << ans << endl;
}
0