結果
問題 | No.1470 Mex Sum |
ユーザー |
![]() |
提出日時 | 2021-04-09 23:13:14 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 2,590 bytes |
コンパイル時間 | 11,911 ms |
コンパイル使用メモリ | 391,204 KB |
実行使用メモリ | 15,760 KB |
最終ジャッジ日時 | 2024-06-25 07:02:52 |
合計ジャッジ時間 | 15,328 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 49 |
コンパイルメッセージ
warning: unnecessary parentheses around assigned value --> src/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; |
ソースコード
//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, } }