結果
| 問題 | No.145 yukiover |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-18 20:26:27 |
| 言語 | Rust (1.92.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,947 bytes |
| 記録 | |
| コンパイル時間 | 22,536 ms |
| コンパイル使用メモリ | 413,984 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-18 20:27:25 |
| 合計ジャッジ時間 | 23,649 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
ソースコード
use fio::*;
fn ok(mut targ: usize, mut cnt: Vec<usize>) -> bool {
// find > y
const S: [u8; 5] = [b'y', b'u', b'k', b'i', b'a' - 1];
for c in S {
for r in ((c + 1)..=b'z').rev() {
targ = targ.saturating_sub(cnt[(r - b'a') as usize]);
cnt[(r - b'a') as usize] = 0;
if targ == 0 {
return true;
}
}
if c == b'a' - 1 {
return false;
}
if cnt[(c - b'a') as usize] < targ {
return false;
}
cnt[(c - b'a') as usize] -= targ;
}
unreachable!()
}
fn solve(s: String) -> usize {
let mut cnt = vec![0; 26];
for c in s.bytes() {
cnt[(c - b'a') as usize] += 1;
}
let mut lo = 0;
let mut hi = s.len() + 1;
while lo + 1 != hi {
let mi = (lo + hi) / 2;
if ok(mi, cnt.clone()) {
lo = mi;
} else {
hi = mi;
}
}
lo
}
fn main() {
let _ = read::<usize>();
let s = read_line();
println!("{}", solve(s));
}
mod fio {
use std::{
cell::RefCell,
convert::TryInto,
fmt::Debug,
io::{BufRead, BufWriter, StdinLock, StdoutLock, stdin, stdout},
str::FromStr,
};
thread_local! {
pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());
pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> = RefCell::new(BufWriter::new(stdout().lock()));
}
#[allow(dead_code)]
pub fn read<T: FromStr>() -> T
where
<T as FromStr>::Err: Debug,
{
read_line().parse().unwrap()
}
#[allow(dead_code)]
pub fn read_vec<T: FromStr>() -> Vec<T>
where
<T as FromStr>::Err: Debug,
{
read_line()
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect()
}
#[allow(dead_code)]
pub fn read_tuple<T, const N: usize>() -> [T; N]
where
T: FromStr + Debug,
<T as FromStr>::Err: Debug,
{
read_vec::<T>().try_into().unwrap()
}
/// whitespace at the end of the line is ignored
pub fn read_line() -> String {
let mut s = String::new();
STDIN.with(|cell| {
cell.borrow_mut().read_line(&mut s).unwrap();
});
String::from_str(s.trim_end()).unwrap()
}
}
#[macro_export]
macro_rules! print {
($($t:tt)*) => {
fio::STDOUT.with(|cell|{
use std::io::Write;
write!(cell.borrow_mut(), $($t)*).unwrap()
})};
}
#[macro_export]
macro_rules! println {
($($t:tt)*) => {
fio::STDOUT.with(|cell| {
use std::io::Write;
writeln!(cell.borrow_mut(), $($t)*).unwrap()
})
};
}
#[macro_export]
macro_rules! flush {
() => {
fio::STDOUT.with(|cell| {
use std::io::Write;
cell.borrow_mut().flush().unwrap()
});
};
}