結果

問題 No.48 ロボットの操縦
ユーザー iwot
提出日時 2019-04-26 18:09:47
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 694 bytes
コンパイル時間 12,292 ms
コンパイル使用メモリ 393,400 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-24 18:22:36
合計ジャッジ時間 13,421 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn main() {
    let x: i32 = read();
    let y: i32 = read();
    let l: i32 = read();

    let get_step = |a: i32| {
        if a != 0 {
            if a % l != 0 {
                a.abs() / l + 1
            } else {
                a.abs() / l
            }
        } else {
            0
        }
    };

    let mut step = 0;
    if y >= 0 {
        step += get_step(y);
        if x != 0 {
            step += 1 + get_step(x);
        }
    } else {
        step += 1 + get_step(x) + 1 + get_step(y);
    }
    println!("{}", step);
}
0