結果

問題 No.1505 Zero-Product Ranges
ユーザー Masaki KitaguchiMasaki Kitaguchi
提出日時 2022-01-16 04:33:06
言語 Rust
(1.77.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 14,362 ms
コンパイル使用メモリ 379,288 KB
実行使用メモリ 10,660 KB
最終ジャッジ日時 2024-05-02 05:22:19
合計ジャッジ時間 16,050 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 28 ms
10,532 KB
testcase_05 AC 12 ms
6,104 KB
testcase_06 AC 12 ms
6,068 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 10 ms
5,972 KB
testcase_09 AC 10 ms
5,940 KB
testcase_10 AC 12 ms
5,944 KB
testcase_11 AC 12 ms
6,092 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 21 ms
9,724 KB
testcase_14 AC 13 ms
6,320 KB
testcase_15 AC 26 ms
10,356 KB
testcase_16 AC 27 ms
10,660 KB
testcase_17 AC 28 ms
10,532 KB
testcase_18 AC 28 ms
10,532 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 26 ms
10,504 KB
testcase_23 AC 27 ms
10,476 KB
testcase_24 AC 26 ms
10,420 KB
testcase_25 AC 25 ms
10,336 KB
testcase_26 AC 27 ms
10,416 KB
testcase_27 AC 26 ms
10,252 KB
testcase_28 AC 28 ms
10,516 KB
testcase_29 AC 27 ms
10,612 KB
testcase_30 AC 27 ms
10,524 KB
testcase_31 AC 26 ms
10,552 KB
testcase_32 AC 14 ms
6,304 KB
testcase_33 AC 12 ms
6,240 KB
testcase_34 AC 14 ms
6,372 KB
testcase_35 AC 11 ms
6,104 KB
testcase_36 AC 12 ms
6,140 KB
testcase_37 AC 13 ms
6,288 KB
testcase_38 AC 13 ms
6,212 KB
testcase_39 AC 12 ms
6,240 KB
testcase_40 AC 13 ms
6,288 KB
testcase_41 AC 14 ms
6,552 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 4 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 3 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().ok().unwrap()
    };
}

fn main() {
    setup! { mut input: SplitWhitespace };

    let n: usize = parse_next!(input);
    let a: Vec<usize> = (0..n).map(|_| parse_next!(input)).collect();

    let mut next_zero = std::collections::HashMap::new();
    {
        let mut zero = None;
        for i in (0..n).rev() {
            if a[i] == 0 {
                zero = Some(i);
            }
            match zero {
                Some(j) => {
                    next_zero.insert(i, j);
                }
                None => {}
            }
        }
    };

    let ans = (|| {
        (0..n).fold(0, |acc, l| match next_zero.get(&l) {
            Some(j) => acc + (n - j),
            None => acc,
        })
    })();

    println!("{}", ans);
}
0