結果

問題 No.1470 Mex Sum
ユーザー maimai
提出日時 2021-04-20 00:27:46
言語 Rust
(1.77.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,692 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 150,264 KB
実行使用メモリ 14,756 KB
最終ジャッジ日時 2023-09-17 08:34:49
合計ジャッジ時間 5,615 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 25 ms
13,324 KB
testcase_13 AC 25 ms
14,276 KB
testcase_14 AC 25 ms
13,292 KB
testcase_15 AC 26 ms
13,312 KB
testcase_16 AC 25 ms
13,060 KB
testcase_17 AC 25 ms
13,816 KB
testcase_18 AC 25 ms
13,008 KB
testcase_19 AC 24 ms
13,080 KB
testcase_20 AC 25 ms
13,076 KB
testcase_21 AC 25 ms
14,340 KB
testcase_22 AC 26 ms
13,540 KB
testcase_23 AC 26 ms
14,072 KB
testcase_24 AC 25 ms
14,756 KB
testcase_25 AC 26 ms
13,600 KB
testcase_26 AC 27 ms
13,600 KB
testcase_27 AC 27 ms
13,592 KB
testcase_28 AC 26 ms
13,992 KB
testcase_29 AC 26 ms
13,596 KB
testcase_30 AC 25 ms
13,584 KB
testcase_31 AC 26 ms
13,584 KB
testcase_32 AC 26 ms
13,580 KB
testcase_33 AC 26 ms
13,540 KB
testcase_34 AC 27 ms
13,640 KB
testcase_35 AC 26 ms
13,584 KB
testcase_36 AC 26 ms
14,568 KB
testcase_37 AC 22 ms
14,568 KB
testcase_38 AC 22 ms
13,516 KB
testcase_39 AC 24 ms
13,428 KB
testcase_40 AC 24 ms
13,468 KB
testcase_41 AC 23 ms
13,516 KB
testcase_42 AC 24 ms
13,432 KB
testcase_43 AC 24 ms
14,192 KB
testcase_44 AC 24 ms
14,244 KB
testcase_45 AC 24 ms
13,472 KB
testcase_46 AC 23 ms
13,432 KB
testcase_47 AC 24 ms
13,408 KB
testcase_48 AC 24 ms
13,520 KB
testcase_49 AC 24 ms
13,504 KB
testcase_50 AC 24 ms
13,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::*;

#[allow(unused)]
struct Scanner<R: std::io::BufRead> {
    stack: VecDeque<String>,
    input: R,
}
impl<R: std::io::BufRead> Scanner<R> {
    fn new(input: R) -> Self {
        Self {
            stack: VecDeque::<String>::new(),
            input: input,
        }
    }
    fn take(&mut self) -> Option<String> {
        if let Some(s) = self.stack.pop_front() {
            return Some(s);
        }
        self.enqueue_from_line();
        self.stack.pop_front()
    }
    fn enqueue_from_line(&mut self) {
        let mut t = String::new();
        self.input.read_line(&mut t).ok();
        t.trim()
            .split_ascii_whitespace()
            .for_each(|s| self.stack.push_back(s.to_owned()));
    }
}

macro_rules! scan {
    ($io:expr => $t:ty) => {
        $io.take().unwrap().parse::<$t>().unwrap()
    };
    ($io:expr => $t:tt * $n:expr) => ((0..$n).map(|_| scan!($io => $t)).collect::<Vec<_>>());
    ($io:expr => $($t:tt),*) => (($(scan!($io => $t)),*));
}

fn main() {
    solve(Scanner::<std::io::StdinLock>::new(std::io::stdin().lock()))
}

fn solve<R: std::io::BufRead>(mut cin: Scanner<R>) {
    let n = scan!(cin => i32);
    let aa = scan!(cin => i32 * n);
    let mut one = 0 as i64;
    let mut two = 0 as i64;
    let mut three = 0 as i64;
    for a in aa {
        match a {
            1 => one += 1,
            2 => two += 1,
            _ => three += 1,
        }
    }
    let mut total = 0;
    total += 2 * one * (one - 1) / 2;
    total += 1 * two * (two - 1) / 2;
    total += 1 * three * (three - 1) / 2;
    total += 3 * one * two;
    total += 2 * one * three;
    total += 1 * two * three;
    println!("{}", total);
}
0