結果

問題 No.1505 Zero-Product Ranges
ユーザー cympfhcympfh
提出日時 2021-05-14 23:40:25
言語 Rust
(1.77.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,907 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 163,540 KB
実行使用メモリ 15,400 KB
最終ジャッジ日時 2024-04-10 04:22:39
合計ジャッジ時間 2,862 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 22 ms
15,296 KB
testcase_04 AC 25 ms
14,524 KB
testcase_05 AC 10 ms
7,040 KB
testcase_06 AC 9 ms
6,944 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 7 ms
6,944 KB
testcase_13 AC 15 ms
9,344 KB
testcase_14 AC 13 ms
8,576 KB
testcase_15 AC 24 ms
13,728 KB
testcase_16 AC 27 ms
14,520 KB
testcase_17 AC 27 ms
14,400 KB
testcase_18 AC 27 ms
14,396 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 26 ms
14,748 KB
testcase_23 AC 26 ms
14,988 KB
testcase_24 AC 26 ms
13,620 KB
testcase_25 AC 25 ms
14,340 KB
testcase_26 AC 26 ms
13,624 KB
testcase_27 AC 25 ms
13,372 KB
testcase_28 AC 26 ms
13,492 KB
testcase_29 AC 26 ms
14,120 KB
testcase_30 AC 27 ms
14,352 KB
testcase_31 AC 26 ms
15,400 KB
testcase_32 AC 14 ms
8,320 KB
testcase_33 AC 13 ms
7,936 KB
testcase_34 AC 15 ms
8,704 KB
testcase_35 AC 11 ms
7,040 KB
testcase_36 AC 11 ms
7,296 KB
testcase_37 AC 13 ms
8,320 KB
testcase_38 AC 12 ms
7,808 KB
testcase_39 AC 13 ms
7,936 KB
testcase_40 AC 14 ms
8,320 KB
testcase_41 AC 15 ms
9,216 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 3 ms
6,940 KB
testcase_44 AC 3 ms
6,944 KB
testcase_45 AC 3 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 3 ms
6,944 KB
testcase_48 AC 3 ms
6,944 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 3 ms
6,940 KB
testcase_51 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, unused_macros, dead_code)]
use std::{cmp::*, collections::*};

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<usize> = sc.vec(n);

    let zeros: Vec<usize> = (0..n).filter(|&i| xs[i] == 0).collect();
    let m = zeros.len();
    let mut cur = 0;

    if zeros.is_empty() {
        put!(0);
        return;
    }

    let mut ans = 0;
    for i in 0..n {
        trace!(i, zeros[cur]);
        ans += n - zeros[cur];
        if i == zeros[cur] {
            cur += 1;
            if cur >= m {
                break;
            }
        }
    }
    put!(ans);
}

// {{{
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Self {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn usize1(&mut self) -> usize {
        self.cin::<usize>() - 1
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}
fn flush() {
    std::io::stdout().flush().unwrap();
}
#[macro_export]
macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
#[macro_export]
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
#[macro_export]
macro_rules! trace {
    ($x:expr) => {
        #[cfg(debug_assertions)]
        eprintln!(">>> {} = {:?}", stringify!($x), $x)
    };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
#[macro_export]
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}
#[macro_export]
macro_rules! ndarray {
    ($x:expr;) => {
        $x
    };
    ($x:expr; $size:expr $( , $rest:expr )*) => {
        vec![ndarray!($x; $($rest),*); $size]
    };
}

// }}}
0