結果

問題 No.1470 Mex Sum
ユーザー Strorkis
提出日時 2021-04-09 21:39:57
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 14,470 ms
コンパイル使用メモリ 385,028 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-25 04:39:22
合計ジャッジ時間 16,805 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 35
権限があれば一括ダウンロードができます

ソースコード

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 * 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