結果

問題 No.1765 While Shining
ユーザー atjh16atjh16
提出日時 2021-12-27 11:39:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 201,128 KB
実行使用メモリ 4,696 KB
最終ジャッジ日時 2023-10-25 10:06:03
合計ジャッジ時間 4,685 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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,348 KB
testcase_10 AC 34 ms
4,604 KB
testcase_11 AC 30 ms
4,496 KB
testcase_12 AC 32 ms
4,564 KB
testcase_13 AC 29 ms
4,480 KB
testcase_14 AC 36 ms
4,668 KB
testcase_15 AC 37 ms
4,668 KB
testcase_16 AC 36 ms
4,668 KB
testcase_17 AC 36 ms
4,668 KB
testcase_18 AC 36 ms
4,668 KB
testcase_19 AC 36 ms
4,668 KB
testcase_20 AC 36 ms
4,668 KB
testcase_21 AC 36 ms
4,668 KB
testcase_22 AC 36 ms
4,668 KB
testcase_23 AC 36 ms
4,668 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n, m;
bool a[200000];
int 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