結果

問題 No.1470 Mex Sum
ユーザー Strorkis
提出日時 2021-04-09 21:45:37
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 16,669 ms
コンパイル使用メモリ 378,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 04:52:19
合計ジャッジ時間 15,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

fn run<'a, I: Iterator<Item = &'a str>>(mut scanner: I) {
    macro_rules! scan {
        ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
        ($t:ty) => (scanner.next().unwrap().parse::<$t>().unwrap());
    }
    macro_rules! input {
        ($($($v:ident)* : $t:tt),* $(,)?) => ($(let $($v)* = scan!($t);)*);
    }
    
    input! {
        n: usize,
        a: [u32; n],
    }

    let mut one = 0;
    let mut two = 0;
    for a in a {
        match a {
            1 => one += 1,
            2 => two += 1,
            _ => (),
        }
    }

    let mut ans: u64 = (n * (n - 1)) as u64 / 2;
    ans += one * (one - 1) / 2;
    ans += one * (n as u64 - one - two);
    ans += one * two * 2;
    println!("{}", ans);
}

fn main() {
    let ref mut buf = Vec::new();
    std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok();
    run(std::str::from_utf8(buf).unwrap().split_whitespace());
}
0