結果
問題 | No.2559 眩しい数直線 |
ユーザー |
|
提出日時 | 2023-12-02 14:51:18 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,927 bytes |
コンパイル時間 | 12,890 ms |
コンパイル使用メモリ | 397,320 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 17:32:51 |
合計ジャッジ時間 | 13,873 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
fn main() { let (n, x) = input_tuple(); let a_b = input_tuple_vec::<usize>(n); let mut list = vec![0; x + 1]; for &(a, b) in &a_b { list[a] = list[a].max(b); let mut light = b; let mut j = a; while light > 0 { light -= 1; j += 1; if j > x { break; } list[j] = list[j].max(light); } let mut light = b; let mut j = a; while light > 0 { light -= 1; j -= 1; if j == 0 { break; } list[j] = list[j].max(light); } // println!("{:?}", list); } let text = &list[1..=x] .iter() .map(|x| x.to_string()) .collect::<Vec<_>>() .join(" "); println!("{}", text); } fn input_tuple<T>() -> (T, T) where T: std::str::FromStr, <T as std::str::FromStr>::Err: std::fmt::Debug, { let stdin = std::io::stdin(); let mut buf = String::new(); stdin.read_line(&mut buf).unwrap(); buf = buf.trim_end().to_owned(); let mut iter = buf.split_whitespace(); let n = iter.next().unwrap().parse().unwrap(); let m = iter.next().unwrap().parse().unwrap(); (n, m) } fn input_tuple_vec<T>(n: usize) -> Vec<(T, T)> where T: std::str::FromStr, <T as std::str::FromStr>::Err: std::fmt::Debug, { // タプルのベクタ let stdin = std::io::stdin(); let mut s_t_d = Vec::with_capacity(n); for _ in 0..n { let mut buf = String::new(); stdin.read_line(&mut buf).unwrap(); buf = buf.trim_end().to_owned(); let mut iter = buf.split_whitespace(); let s = iter.next().unwrap().parse().unwrap(); let t = iter.next().unwrap().parse().unwrap(); // let d = iter.next().unwrap().parse().unwrap(); s_t_d.push((s, t)); } s_t_d }