Skip to content

Commit

Permalink
abc329 a, b, c, d, e
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Nov 20, 2023
1 parent caafe2f commit 154a646
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 54 deletions.
12 changes: 5 additions & 7 deletions cargo-atcoder-1.70.0/contests/abc329/src/bin/a.rs
Expand Up @@ -4,12 +4,10 @@ fn main() {
input! {
s: Chars,
};
let mut t = vec![];
for s_i in s {
t.push(s_i);
t.push(' ');
}
t.pop();
let ans = t.into_iter().collect::<String>();
let ans = s
.into_iter()
.map(|s_i| s_i.to_string())
.collect::<Vec<String>>()
.join(" ");
println!("{}", ans);
}
8 changes: 2 additions & 6 deletions cargo-atcoder-1.70.0/contests/abc329/src/bin/b.rs
@@ -1,15 +1,11 @@
use std::collections::BTreeSet;

use proconio::input;

fn main() {
input! {
n: usize,
a: [usize; n],
};
let set = a.into_iter().collect::<BTreeSet<usize>>();
let mut it = set.iter().rev();
it.next();
let ans = it.next().unwrap();
let max = *a.iter().max().unwrap();
let ans = a.into_iter().filter(|a_i| a_i != &max).max().unwrap();
println!("{}", ans);
}
42 changes: 15 additions & 27 deletions cargo-atcoder-1.70.0/contests/abc329/src/bin/c.rs
@@ -1,38 +1,26 @@
use proconio::{input, marker::Chars};

macro_rules! chmax {
($max_v: expr, $v: expr) => {
if $v > $max_v {
$max_v = $v;
true
} else {
false
}
};
}

fn main() {
input! {
_n: usize,
s: Chars,
};
let mut set = vec![0_usize; 26];
let mut prev = vec![];
for s_i in s {
match prev.last() {
Some(c) => {
if *c == s_i {
prev.push(s_i);
} else {
prev = vec![s_i];
}
}
None => {
prev = vec![s_i];
}
let mut t = vec![(s[0], 1)];
for c in s.into_iter().skip(1) {
let (prev, len) = t.pop().unwrap();
if prev == c {
t.push((prev, len + 1));
} else {
t.push((prev, len));
t.push((c, 1));
}
chmax!(set[(prev[0] as u8 - b'a') as usize], prev.len());
}
let ans = set.into_iter().sum::<usize>();

let mut count = vec![0_usize; 26];
for (c, len) in t {
let index = (c as u8 - b'a') as usize;
count[index] = count[index].max(len);
}
let ans = count.into_iter().sum::<usize>();
println!("{}", ans);
}
19 changes: 9 additions & 10 deletions cargo-atcoder-1.70.0/contests/abc329/src/bin/d.rs
@@ -1,4 +1,4 @@
use std::collections::BTreeSet;
use std::collections::{BTreeMap, BTreeSet};

use proconio::{input, marker::Usize1};

Expand All @@ -11,20 +11,19 @@ fn main() {

let mut ans = vec![];
let mut count = vec![0_usize; n];
let mut map = vec![BTreeSet::new(); 200_000 + 1];
let mut keys = BTreeSet::new();
let mut map: BTreeMap<usize, BTreeSet<usize>> = BTreeMap::new();
for a_i in a {
let entry = &mut map[count[a_i]];
entry.remove(&a_i);
if entry.is_empty() {
keys.remove(&count[a_i]);
if let Some(set) = map.get_mut(&count[a_i]) {
set.remove(&a_i);
if set.is_empty() {
map.remove(&count[a_i]);
}
}

count[a_i] += 1;
keys.insert(count[a_i]);
map[count[a_i]].insert(a_i);
map.entry(count[a_i]).or_insert(BTreeSet::new()).insert(a_i);

let top = *map[*keys.iter().rev().next().unwrap()].first().unwrap();
let top = *map.iter().rev().next().unwrap().1.first().unwrap();
ans.push(top);
}

Expand Down
44 changes: 40 additions & 4 deletions cargo-atcoder-1.70.0/contests/abc329/src/bin/e.rs
@@ -1,10 +1,46 @@
use proconio::{input, marker::Usize1};
use std::collections::VecDeque;

use proconio::{input, marker::Chars};

fn is_match(s: &[char], t: &[char], i: usize) -> bool {
for j in 0..t.len() {
if i + j >= s.len() {
return false;
}
if s[i + j] != '.' && s[i + j] != t[j] {
return false;
}
}
true
}

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

let mut queue = VecDeque::new();
for i in 0..n {
if is_match(&s, &t, i) {
s[i..i + m].fill('.');
queue.push_back(i);
}
}

let mut used = vec![false; n];
while let Some(prev) = queue.pop_front() {
for i in prev.saturating_sub(t.len() - 1)..prev + t.len() - 1 {
if !used[i] && is_match(&s, &t, i) {
s[i..i + m].fill('.');
queue.push_back(i);
used[i] = true;
}
}
}

let ans = s.iter().all(|c| c == &'.');
println!("{}", if ans { "Yes" } else { "No" });
}

0 comments on commit 154a646

Please sign in to comment.