結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-03 19:25:59 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 5,000 ms |
| コード長 | 1,299 bytes |
| コンパイル時間 | 15,399 ms |
| コンパイル使用メモリ | 377,976 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-07-03 01:12:38 |
| 合計ジャッジ時間 | 14,659 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
use std::io::*;
fn main() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.trim().split_whitespace();
let t: usize = itr.next().unwrap().parse().unwrap();
let mut out = Vec::new();
for _ in 0..t {
let n: usize = itr.next().unwrap().parse().unwrap();
let a: Vec<usize> = (0..n)
.map(|_| itr.next().unwrap().parse().unwrap())
.collect();
let mut map = std::collections::HashMap::new();
let mut bh = std::collections::BinaryHeap::new();
for i in 0..n {
let p = map.entry(a[i]).or_insert(0);
*p += 1;
}
for (&_k, &v) in map.iter() {
bh.push(v);
}
let mut ans = 0;
while bh.len() > 2 {
let a = bh.pop().unwrap();
let b = bh.pop().unwrap();
let c = bh.pop().unwrap();
if a > 0 {
bh.push(a - 1);
}
if b > 0 {
bh.push(b - 1);
}
if c > 0 {
bh.push(c - 1);
}
if a > 0 && b > 0 && c > 0 {
ans += 1;
}
}
writeln!(out, "{}", ans).ok();
}
stdout().write_all(&out).unwrap();
}