結果

問題 No.1505 Zero-Product Ranges
ユーザー Manuel1024Manuel1024
提出日時 2021-05-14 22:59:09
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 451 ms
使用メモリ 4,768 KB
最終ジャッジ日時 2022-11-25 20:59:44
合計ジャッジ時間 3,358 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,376 KB
testcase_01 AC 1 ms
3,508 KB
testcase_02 AC 1 ms
3,480 KB
testcase_03 AC 24 ms
4,624 KB
testcase_04 AC 26 ms
4,672 KB
testcase_05 AC 11 ms
3,632 KB
testcase_06 AC 11 ms
3,712 KB
testcase_07 AC 8 ms
3,712 KB
testcase_08 AC 10 ms
3,712 KB
testcase_09 AC 10 ms
3,572 KB
testcase_10 AC 9 ms
3,616 KB
testcase_11 AC 11 ms
3,708 KB
testcase_12 AC 8 ms
3,640 KB
testcase_13 AC 16 ms
3,920 KB
testcase_14 AC 14 ms
3,904 KB
testcase_15 AC 24 ms
4,768 KB
testcase_16 AC 27 ms
4,636 KB
testcase_17 AC 28 ms
4,732 KB
testcase_18 AC 28 ms
4,668 KB
testcase_19 AC 1 ms
3,512 KB
testcase_20 AC 1 ms
3,424 KB
testcase_21 AC 1 ms
3,384 KB
testcase_22 AC 26 ms
4,752 KB
testcase_23 AC 26 ms
4,672 KB
testcase_24 AC 25 ms
4,716 KB
testcase_25 AC 24 ms
4,372 KB
testcase_26 AC 27 ms
4,712 KB
testcase_27 AC 25 ms
4,436 KB
testcase_28 AC 24 ms
4,472 KB
testcase_29 AC 25 ms
4,664 KB
testcase_30 AC 27 ms
4,716 KB
testcase_31 AC 26 ms
4,700 KB
testcase_32 AC 15 ms
3,900 KB
testcase_33 AC 14 ms
3,908 KB
testcase_34 AC 16 ms
3,944 KB
testcase_35 AC 12 ms
3,648 KB
testcase_36 AC 12 ms
3,620 KB
testcase_37 AC 14 ms
3,876 KB
testcase_38 AC 13 ms
3,944 KB
testcase_39 AC 15 ms
3,872 KB
testcase_40 AC 15 ms
3,972 KB
testcase_41 AC 18 ms
3,964 KB
testcase_42 AC 3 ms
3,552 KB
testcase_43 AC 3 ms
3,524 KB
testcase_44 AC 3 ms
3,496 KB
testcase_45 AC 4 ms
3,508 KB
testcase_46 AC 2 ms
3,596 KB
testcase_47 AC 4 ms
3,624 KB
testcase_48 AC 2 ms
3,608 KB
testcase_49 AC 2 ms
3,552 KB
testcase_50 AC 3 ms
3,580 KB
testcase_51 AC 4 ms
3,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &p: a) cin >> p;
    vector<int> memo(n, -1);
    if(a[n-1] == 0) memo[n-1] = n-1;
    for(int i = n-2; i >= 0; i--){
        memo[i] = memo[i+1];
        if(a[i] == 0) memo[i] = i;
    }

    long long int ans = 0;
    for(int i = 0; i < n; i++){
        if(memo[i] != -1){
            ans += n-memo[i];
        }
    }
    cout << ans << endl;
    return 0;
}
0