Skip to content

Commit

Permalink
past202010-open f
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 15, 2024
1 parent 83a0c76 commit e217b12
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions cargo-atcoder-1.70.0/contests/past202010-open/src/bin/f.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
use proconio::{input, marker::Usize1};
use std::{
cmp::Reverse,
collections::{BTreeMap, HashMap},
};

use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
k: usize,
s: [String; n],
};
let ans = n - a.len();
println!("{}", ans);

let mut map = HashMap::new();
for s_i in s {
*map.entry(s_i).or_insert(0_usize) += 1;
}

let mut map2 = BTreeMap::new();
for (s, c) in map {
map2.entry(Reverse(c)).or_insert_with(Vec::new).push(s);
}

let mut sum = 0_usize;
for (_, ss) in map2.into_iter() {
if sum + ss.len() < k {
sum += ss.len();
continue;
}
if ss.len() == 1 {
println!("{}", ss[0]);
} else {
println!("AMBIGUOUS");
}
return;
}
}

0 comments on commit e217b12

Please sign in to comment.