結果
問題 | No.1470 Mex Sum |
ユーザー |
![]() |
提出日時 | 2021-04-09 21:47:46 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 3,605 bytes |
コンパイル時間 | 12,761 ms |
コンパイル使用メモリ | 382,580 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 04:56:12 |
合計ジャッジ時間 | 14,706 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 49 |
ソースコード
#![allow(unused_macros)]#![allow(dead_code)]#![allow(unused_imports)]// # ファイル構成// - use 宣言// - lib モジュール// - main 関数// - basic モジュール//// 常に使うテンプレートライブラリは basic モジュール内にあります。// 問題に応じて使うライブラリ lib モジュール内にコピペしています。// ライブラリのコードはこちら → https://github.com/RheoTommy/at_coder// Twitter はこちら → https://twitter.com/RheoTommyuse std::collections::*;use std::io::{stdout, BufWriter, Write};use crate::basic::*;use crate::lib::*;pub mod lib {}fn main() {let mut io = IO::new();let n = io.next_usize();let a = io.next_vec::<i64>(n);let one = a.iter().filter(|&&ai| ai == 1).count();let two = a.iter().filter(|&&ai| ai == 2).count();let mut ans = 0;if n != one {ans += (n - one) * (n - one - 1) / 2;}if one != 0 {ans += one * (one - 1);}if n != one + two {ans += one * (n - one - two) * 2}ans += one * two * 3;io.println(ans);}pub mod basic {pub const U_INF: u64 = (1 << 60) + (1 << 30);pub const I_INF: i64 = (1 << 60) + (1 << 30);pub struct IO {iter: std::str::SplitAsciiWhitespace<'static>,buf: std::io::BufWriter<std::io::StdoutLock<'static>>,}impl IO {pub fn new() -> Self {use std::io::*;let mut input = String::new();std::io::stdin().read_to_string(&mut input).unwrap();let input = Box::leak(input.into_boxed_str());let out = Box::new(stdout());IO {iter: input.split_ascii_whitespace(),buf: BufWriter::new(Box::leak(out).lock()),}}pub fn next_str(&mut self) -> &str {self.iter.next().unwrap()}pub fn next<T: std::str::FromStr>(&mut self) -> Twhere<T as std::str::FromStr>::Err: std::fmt::Debug,{self.iter.next().unwrap().parse().unwrap()}pub fn next_usize(&mut self) -> usize {self.next()}pub fn next_uint(&mut self) -> u64 {self.next()}pub fn next_int(&mut self) -> i64 {self.next()}pub fn next_float(&mut self) -> f64 {self.next()}pub fn next_chars(&mut self) -> std::str::Chars {self.next_str().chars()}pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T>where<T as std::str::FromStr>::Err: std::fmt::Debug,{(0..n).map(|_| self.next()).collect::<Vec<_>>()}pub fn print<T: std::fmt::Display>(&mut self, t: T) {use std::io::Write;write!(self.buf, "{}", t).unwrap();}pub fn println<T: std::fmt::Display>(&mut self, t: T) {self.print(t);self.print("\n");}pub fn print_iter<T: std::fmt::Display, I: Iterator<Item = T>>(&mut self,mut iter: I,sep: &str,) {if let Some(v) = iter.next() {self.print(v);for vi in iter {self.print(sep);self.print(vi);}}self.print("\n");}pub fn flush(&mut self) {use std::io::Write;self.buf.flush().unwrap();}}}