Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" }); | ||
} |