結果
問題 | No.1470 Mex Sum |
ユーザー |
|
提出日時 | 2022-11-05 22:07:08 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 872 bytes |
コンパイル時間 | 27,347 ms |
コンパイル使用メモリ | 377,828 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 15:24:54 |
合計ジャッジ時間 | 13,776 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 49 |
ソースコード
fn main() {let mut n = String::new();std::io::stdin().read_line(&mut n).ok();let n: usize = n.trim().parse().unwrap();let mut a = String::new();std::io::stdin().read_line(&mut a).ok();let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let mut mapping = vec![0usize; 3];for i in 0..n {let idx = (a[i]-1).min(2);mapping[idx] += 1;}let mut result = 0usize;if mapping[0] > 1 {result += mapping[0] * (mapping[0]-1) / 2 * 2;}result += mapping[0] * mapping[1] * 3;result += mapping[0] * mapping[2] * 2;if mapping[1] > 1 {result += mapping[1] * (mapping[1]-1) / 2 * 1;}result += mapping[1] * mapping[2] * 1;if mapping[2] > 1 {result += mapping[2] * (mapping[2]-1) / 2 * 1;}println!("{}", result);}