結果

問題 No.1765 While Shining
ユーザー atjh16atjh16
提出日時 2021-12-27 11:41:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 200,940 KB
実行使用メモリ 5,352 KB
最終ジャッジ日時 2023-10-25 10:07:59
合計ジャッジ時間 3,528 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 23 ms
4,716 KB
testcase_10 AC 34 ms
5,240 KB
testcase_11 AC 30 ms
5,036 KB
testcase_12 AC 33 ms
5,164 KB
testcase_13 AC 30 ms
5,008 KB
testcase_14 AC 36 ms
5,352 KB
testcase_15 AC 36 ms
5,352 KB
testcase_16 AC 37 ms
5,352 KB
testcase_17 AC 36 ms
5,352 KB
testcase_18 AC 37 ms
5,352 KB
testcase_19 AC 36 ms
5,352 KB
testcase_20 AC 37 ms
5,352 KB
testcase_21 AC 36 ms
5,352 KB
testcase_22 AC 36 ms
5,352 KB
testcase_23 AC 35 ms
5,352 KB
testcase_24 AC 35 ms
5,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n;
bool a[200000];
long long m = 0;
long long b[200000];

int main(){
    cin >> n;
    
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    for(int i = n - 2; i >= 0; i--){
        if(a[i]){
            bool f = 0;
            int j = i + 1;
            b[i]++;
            
            while(j < n - 1 && a[j] == f){
                if(b[j] > 0){
                    b[i] += b[j];
                    break;
                }
                
                b[i]++;
                f = !f;
                j++;
            }
                        
            m += b[i];
        }
    }
    
    cout << m << endl;
}
0