結果

問題 No.2922 Rose Garden
ユーザー ぱるまぱるま
提出日時 2024-10-12 15:19:38
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 14 ms / 3,000 ms
コード長 5,323 bytes
コンパイル時間 13,200 ms
コンパイル使用メモリ 379,420 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-10-12 15:20:04
合計ジャッジ時間 15,528 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,248 KB
testcase_01 AC 6 ms
5,248 KB
testcase_02 AC 8 ms
5,248 KB
testcase_03 AC 13 ms
5,248 KB
testcase_04 AC 8 ms
5,248 KB
testcase_05 AC 7 ms
5,248 KB
testcase_06 AC 5 ms
5,248 KB
testcase_07 AC 11 ms
5,248 KB
testcase_08 AC 3 ms
5,248 KB
testcase_09 AC 12 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 8 ms
5,248 KB
testcase_13 AC 10 ms
5,248 KB
testcase_14 AC 3 ms
5,248 KB
testcase_15 AC 8 ms
5,248 KB
testcase_16 AC 10 ms
5,248 KB
testcase_17 AC 14 ms
5,248 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 6 ms
5,248 KB
testcase_20 AC 10 ms
5,248 KB
testcase_21 AC 13 ms
5,248 KB
testcase_22 AC 7 ms
5,248 KB
testcase_23 AC 12 ms
5,248 KB
testcase_24 AC 3 ms
5,248 KB
testcase_25 AC 6 ms
5,248 KB
testcase_26 AC 11 ms
5,248 KB
testcase_27 AC 12 ms
5,248 KB
testcase_28 AC 10 ms
5,248 KB
testcase_29 AC 9 ms
5,248 KB
testcase_30 AC 1 ms
5,248 KB
testcase_31 AC 1 ms
5,248 KB
testcase_32 AC 2 ms
5,248 KB
testcase_33 AC 1 ms
5,248 KB
testcase_34 AC 1 ms
5,248 KB
testcase_35 AC 1 ms
5,248 KB
testcase_36 AC 2 ms
5,248 KB
testcase_37 AC 2 ms
5,248 KB
testcase_38 AC 2 ms
5,248 KB
testcase_39 AC 2 ms
5,248 KB
testcase_40 AC 9 ms
5,248 KB
testcase_41 AC 5 ms
5,248 KB
testcase_42 AC 14 ms
5,248 KB
testcase_43 AC 7 ms
5,248 KB
testcase_44 AC 14 ms
5,248 KB
testcase_45 AC 4 ms
5,248 KB
testcase_46 AC 14 ms
5,376 KB
testcase_47 AC 10 ms
5,248 KB
testcase_48 AC 3 ms
5,248 KB
testcase_49 AC 12 ms
5,248 KB
testcase_50 AC 1 ms
5,248 KB
testcase_51 AC 1 ms
5,248 KB
testcase_52 AC 1 ms
5,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: field `n` is never read
 --> src/main.rs:4:5
  |
3 | struct Problem {
  |        ------- field in this struct
4 |     n: usize,
  |     ^
  |
  = note: `Problem` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
  = note: `#[warn(dead_code)]` on by default

ソースコード

diff #

//#[derive_readable]
#[derive(Debug, Clone)]
struct Problem {
    n: usize,
    s: i64,
    b: i64,
    hs: Vec<i64>,
}

impl Problem {
    fn read() -> Problem {
        input! {
            n: usize,
            s: i64,
            b: i64,
            hs: [i64; n],
        }
        Problem { n, s, b, hs }
    }

    fn solve(&self) -> Answer {
        let s = self.s; // 地面についたときのスタミナ
        let b = self.b; // スタミナ1消費して移動できる高さ
        let hs = &self.hs;
        let mut current_stamina = s;
        let mut current_height = self.hs[0];

        for &h in &hs[1..] {
            if h > current_height {
                let height_diff = h - current_height;
                let consuming_stamina = if height_diff % b == 0 {
                    height_diff / b
                } else {
                    height_diff / b + 1
                };
                current_stamina -= consuming_stamina;
                current_height = h;
                if current_stamina < 0 {
                    return Answer { ans: false };
                }
                current_stamina = s;
            }
        }
        Answer { ans: true }
    }

    #[allow(dead_code)]
    fn solve_naive(&self) -> Answer {
        todo!();
        // let ans = 0;
        // Answer { ans }
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
struct Answer {
    ans: bool,
}

impl Answer {
    fn print(&self) {
        print_yesno(self.ans);
    }
}

fn main() {
    Problem::read().solve().print();
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use super::*;
    #[allow(unused_imports)]
    use rand::{rngs::SmallRng, seq::SliceRandom, *};

    #[test]
    fn test_problem() {
        assert_eq!(1 + 1, 2);
    }

    #[allow(dead_code)]
    #[derive(Debug)]
    struct WrongTestCase {
        problem: Problem,
        main_ans: Answer,
        naive_ans: Answer,
    }

    #[allow(dead_code)]
    fn check(p: &Problem) -> Option<WrongTestCase> {
        let main_ans = p.solve();
        let naive_ans = p.solve_naive();
        if main_ans != naive_ans {
            Some(WrongTestCase {
                problem: p.clone(),
                main_ans,
                naive_ans,
            })
        } else {
            None
        }
    }

    #[allow(dead_code)]
    fn make_random_problem(rng: &mut SmallRng) -> Problem {
        todo!()
        // let n = rng.gen_range(1..=10);
        // let p = Problem { _a: n };
        // println!("{:?}", &p);
        // p
    }

    #[allow(unreachable_code)]
    #[test]
    fn test_with_naive() {
        let num_tests = 0;
        let max_wrong_case = 10; // この件数間違いが見つかったら打ち切り
        let mut rng = SmallRng::seed_from_u64(42);
        // let mut rng = SmallRng::from_entropy();
        let mut wrong_cases: Vec<WrongTestCase> = vec![];
        for _ in 0..num_tests {
            let p = make_random_problem(&mut rng);
            let result = check(&p);
            if let Some(wrong_test_case) = result {
                wrong_cases.push(wrong_test_case);
            }
            if wrong_cases.len() >= max_wrong_case {
                break;
            }
        }

        if !wrong_cases.is_empty() {
            for t in &wrong_cases {
                println!("{:?}", t.problem);
                println!("main ans : {:?}", t.main_ans);
                println!("naive ans: {:?}", t.naive_ans);
                println!();
            }
            println!("{} cases are wrong.", wrong_cases.len());
            panic!();
        }
    }
}

// ====== import ======
#[allow(unused_imports)]
use proconio::{
    derive_readable, fastout, input,
    marker::{Bytes, Chars, Usize1},
};
#[allow(unused_imports)]
use std::cmp::Reverse;
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

// ====== output func ======
#[allow(unused_imports)]
use print_vec::*;
pub mod print_vec {

    use proconio::fastout;
    #[fastout]
    pub fn print_vec<T: std::fmt::Debug>(arr: &[T]) {
        for a in arr {
            println!("{:?}", a);
        }
    }
    #[fastout]
    pub fn print_vec_1line<T: std::fmt::Debug>(arr: &[T]) {
        let msg = arr
            .iter()
            .map(|x| format!("{:?}", x))
            .collect::<Vec<String>>()
            .join(" ");
        println!("{}", msg);
    }
    #[fastout]
    pub fn print_vec2<T: std::fmt::Debug>(arr: &Vec<Vec<T>>) {
        for row in arr {
            let msg = row
                .iter()
                .map(|x| format!("{:?}", x))
                .collect::<Vec<String>>()
                .join(" ");
            println!("{}", msg);
        }
    }
    pub fn print_bytes(bytes: &[u8]) {
        let msg = String::from_utf8(bytes.to_vec()).unwrap();
        println!("{}", msg);
    }
    pub fn print_chars(chars: &[char]) {
        let msg = chars.iter().collect::<String>();
        println!("{}", msg);
    }
    #[fastout]
    pub fn print_vec_bytes(vec_bytes: &[Vec<u8>]) {
        for row in vec_bytes {
            let msg = String::from_utf8(row.to_vec()).unwrap();
            println!("{}", msg);
        }
    }
}

#[allow(unused)]
fn print_yesno(ans: bool) {
    let msg = if ans { "Yes" } else { "No" };
    println!("{}", msg);
}

// ====== snippet ======
0