結果
| 問題 | No.1470 Mex Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-05 22:26:25 |
| 言語 | Rust (1.97.1 + proconio + num + itertools + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 7 ms / 2,000 ms |
| + 821µs | |
| コード長 | 1,137 bytes |
| 記録 | |
| コンパイル時間 | 4,965 ms |
| コンパイル使用メモリ | 199,424 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-05 22:27:11 |
| 合計ジャッジ時間 | 9,921 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 49 |
ソースコード
use proconio::input;
use std::collections::HashMap;
fn main() {
input! {
n: usize,
a: [usize; n]
}
// x <= y
// if x == 1 かつ y == 1 => 2
// if x == 1 かつ y == 2 => 3
// if x == 1 かつ 3 <= y => 2
// else => 1
let mut map = HashMap::new();
for &x in &a {
*map.entry(if x != 1 && x != 2 { 3 } else { x }).or_insert(0) += 1;
}
let mut res = 0_usize;
let one = map.get(&1);
let two = map.get(&2);
let other = map.get(&3);
if let Some(&onec) = one {
res += 2 * onec * (onec - 1) / 2;
if let Some(&tc) = two {
res += 3 * onec * tc;
}
if let Some(&oc) = other {
res += 2 * onec * oc;
}
}
match (two, other) {
(Some(tc), Some(oc)) => {
res += tc * (tc - 1) / 2;
res += oc * (oc - 1) / 2;
res += oc * tc;
}
(None, Some(oc)) => {
res += oc * (oc - 1) / 2;
}
(Some(tc), None) => {
res += tc * (tc - 1) / 2;
}
(None, None) => {}
}
println!("{res}");
}