AtCoder ABC230 A-E Rust
AtCoder ABC230 A-E Rust
A - AtCoder Quiz 3
42以上なら1追加する問題.
rustの文字列フォーマットは{:03}
みたいな感じで書く. 毎回忘れる.
use proconio::{fastout, input}; #[allow(non_snake_case)] #[fastout] fn main() { input! { mut N: usize, } if N >= 42 { N += 1; } println!("AGC{:03}", N); }
B - Triple Metre
文字列Sが文字列Tの部分文字列であるか判定する問題. Tはoxx
が[tex: 105]個繰り返すとあるが, 実際には4回程度で良い.(Sが10文字以下であるため)その中から部分文字列を全探索.
use proconio::{fastout, input}; const YES: &str = "Yes"; const NO: &str = "No"; #[allow(non_snake_case)] #[fastout] fn main() { input! { S: String, } let T = "oxxoxxoxxoxx"; for i in 0..3 { if T[i..(i + S.len())] == S[..] { println!("{}", YES); return; } } println!("{}", NO); }
C - X drawin
条件を整理して, 塗る問題. 条件を整理できなかったので解けなかった. 悲しい.
実際は図に起こすとよくわかる.
use proconio::{fastout, input}; const YES: &str = "Yes"; const NO: &str = "No"; #[allow(non_snake_case)] #[fastout] fn main() { input! { S: String, } let T = "oxxoxxoxxoxx"; for i in 0..3 { if T[i..(i + S.len())] == S[..] { println!("{}", YES); return; } } println!("{}", NO); }
D - Destroyer Takahashi
普通に区間スケジューリング問題. 右端を幅Dで調整することに注意.
use proconio::{fastout, input}; #[allow(non_snake_case)] #[fastout] fn main() { input! { N: usize, D: usize, mut LR: [(usize, usize); N] } LR.sort_unstable_by_key(|(_, r)| *r); let mut ans = 0; let mut x = 0; for &(l, r) in LR.iter() { if x < l { ans += 1; x = r + D - 1; } } println!("{}", ans); }