結果

問題 No.1470 Mex Sum
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2021-04-09 23:13:14
言語 Rust
(1.72.1)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 2,590 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 154,868 KB
実行使用メモリ 15,580 KB
最終ジャッジ日時 2023-09-07 12:58:48
合計ジャッジ時間 4,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,384 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 40 ms
14,132 KB
testcase_13 AC 40 ms
13,936 KB
testcase_14 AC 40 ms
14,816 KB
testcase_15 AC 41 ms
15,228 KB
testcase_16 AC 41 ms
13,776 KB
testcase_17 AC 40 ms
13,788 KB
testcase_18 AC 39 ms
13,748 KB
testcase_19 AC 40 ms
14,776 KB
testcase_20 AC 40 ms
13,804 KB
testcase_21 AC 42 ms
15,580 KB
testcase_22 AC 43 ms
14,308 KB
testcase_23 AC 41 ms
14,792 KB
testcase_24 AC 41 ms
14,288 KB
testcase_25 AC 42 ms
14,284 KB
testcase_26 AC 42 ms
15,384 KB
testcase_27 AC 41 ms
14,668 KB
testcase_28 AC 41 ms
14,240 KB
testcase_29 AC 41 ms
14,312 KB
testcase_30 AC 42 ms
15,024 KB
testcase_31 AC 42 ms
14,304 KB
testcase_32 AC 43 ms
14,288 KB
testcase_33 AC 41 ms
15,392 KB
testcase_34 AC 40 ms
14,724 KB
testcase_35 AC 42 ms
14,296 KB
testcase_36 AC 42 ms
14,984 KB
testcase_37 AC 26 ms
14,224 KB
testcase_38 AC 26 ms
14,300 KB
testcase_39 AC 26 ms
14,240 KB
testcase_40 AC 36 ms
14,272 KB
testcase_41 AC 37 ms
15,004 KB
testcase_42 AC 37 ms
14,948 KB
testcase_43 AC 36 ms
15,120 KB
testcase_44 AC 37 ms
14,224 KB
testcase_45 AC 36 ms
14,212 KB
testcase_46 AC 36 ms
14,296 KB
testcase_47 AC 36 ms
14,284 KB
testcase_48 AC 36 ms
15,080 KB
testcase_49 AC 36 ms
14,308 KB
testcase_50 AC 37 ms
14,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around assigned value
  --> Main.rs:23:16
   |
23 |         sum += (n - i - 1);
   |                ^         ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
23 -         sum += (n - i - 1);
23 +         sum += n - i - 1;
   |

warning: 1 warning emitted

ソースコード

diff #

//use proconio::input;
fn main() {
    let t = std::io::stdin();
    let mut read = snio::Reader::new(t.lock());
    let n = read.usize();
    let mut a:Vec<_> = (0..n).map(|_| read.i64()).collect();
    a.sort();
    let mut cnt_one = 0;
    let mut sum = 0;
    for i in 0..n {
        if a[i] == 1 {
            cnt_one += 1;
        }else {
            if a[i] == 2 {
                sum += cnt_one * 3;
            }else{
                sum += cnt_one * 2;
            }
        }
    }
    sum += cnt_one * (cnt_one - 1) / 2 * 2;
    for i in cnt_one..n {
        sum += (n - i - 1);
    }
    println!("{}",sum);
}

#[allow(dead_code)]
pub mod snio {
    pub struct Reader<R: std::io::BufRead> {
        reader: R,
        buf: std::collections::VecDeque<String>,
    }

    impl<R: std::io::BufRead> Reader<R> {
        pub fn new(reader: R) -> Self {
            Self {
                reader,
                buf: std::collections::VecDeque::new(),
            }
        }
        fn load(&mut self) {
            while self.buf.is_empty() {
                let mut s = String::new();
                let length = self.reader.read_line(&mut s).unwrap();
                if length == 0 {
                    break;
                }
                self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
            }
        }
        pub fn string(&mut self) -> String {
            self.load();
            self.buf.pop_front().unwrap_or_else(|| panic!("input ended"))
        }
        pub fn char(&mut self) -> char {
            let string = self.string();
            let mut chars = string.chars();
            let res = chars.next().unwrap();
            assert!(chars.next().is_none(), "invalid input!");
            res
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
        pub fn read<T: std::str::FromStr>(&mut self) -> T
            where
                <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            self.string().parse::<T>().expect("Failed to parse the input.")
        }
    }
    macro_rules! definition_of_reader_of_numbers {
            ($($ty:tt,)*) => {
                impl <R:std::io::BufRead> Reader<R> {
                    $(
                    #[inline]
                    pub fn $ty (&mut self) -> $ty {
                        self.read::<$ty>()
                    }
                    )*
                }
            }
        }
    definition_of_reader_of_numbers! {
        u8,u16,u32,u64,usize,
        i8,i16,i32,i64,isize,
    }
}
0