結果

問題 No.1470 Mex Sum
ユーザー maimai
提出日時 2021-04-19 20:08:00
言語 Rust
(1.77.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,577 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 151,364 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2023-09-17 08:21:59
合計ジャッジ時間 4,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 24 ms
14,592 KB
testcase_13 AC 25 ms
13,112 KB
testcase_14 AC 24 ms
14,324 KB
testcase_15 AC 26 ms
13,332 KB
testcase_16 AC 25 ms
12,992 KB
testcase_17 AC 24 ms
14,176 KB
testcase_18 AC 24 ms
13,008 KB
testcase_19 AC 24 ms
12,996 KB
testcase_20 AC 23 ms
13,028 KB
testcase_21 AC 25 ms
13,556 KB
testcase_22 AC 25 ms
13,580 KB
testcase_23 AC 25 ms
13,596 KB
testcase_24 AC 26 ms
13,516 KB
testcase_25 AC 25 ms
13,500 KB
testcase_26 AC 25 ms
13,600 KB
testcase_27 AC 25 ms
13,556 KB
testcase_28 AC 25 ms
13,600 KB
testcase_29 AC 25 ms
13,592 KB
testcase_30 AC 25 ms
14,560 KB
testcase_31 AC 25 ms
13,568 KB
testcase_32 AC 25 ms
13,620 KB
testcase_33 AC 25 ms
13,540 KB
testcase_34 AC 26 ms
13,604 KB
testcase_35 AC 26 ms
13,544 KB
testcase_36 AC 25 ms
13,532 KB
testcase_37 AC 23 ms
13,448 KB
testcase_38 AC 23 ms
13,436 KB
testcase_39 AC 22 ms
13,472 KB
testcase_40 AC 23 ms
13,472 KB
testcase_41 AC 23 ms
13,436 KB
testcase_42 AC 23 ms
13,472 KB
testcase_43 AC 23 ms
13,468 KB
testcase_44 AC 23 ms
13,432 KB
testcase_45 AC 23 ms
13,452 KB
testcase_46 AC 23 ms
14,128 KB
testcase_47 AC 23 ms
14,196 KB
testcase_48 AC 23 ms
13,516 KB
testcase_49 AC 22 ms
13,456 KB
testcase_50 AC 23 ms
13,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::*;

#[allow(unused)]
struct Scanner {
    stack: VecDeque<String>,
    input: std::io::Stdin,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stack: VecDeque::<String>::new(),
            input: std::io::stdin(),
        }
    }
    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() {
    let mut cin = Scanner::new();
    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