結果

問題 No.48 ロボットの操縦
コンテスト
ユーザー yo-kondo
提出日時 2019-03-03 16:22:52
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,357 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 626 ms
コンパイル使用メモリ 191,288 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-08 08:34:39
合計ジャッジ時間 1,228 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::io::stdin;

/// エントリポイント
fn main() {
    let in1 = read_line();
    let in2 = read_line();
    let in3 = read_line();
    println!("{}", count_order(in1, in2, in3));
}

/// 移動先に到達するまでに必要な最小の命令回数を計算します。
///
/// ## arguments
/// * `east_west` - 目的地の東西方向
/// * `north_south` - 目的地の南北方向
/// * `max_distance` - ロボットが1命令につき前進することができる最大の距離
fn count_order(east_west: String, north_south: String, max_distance: String) -> i32 {
    let mut num = 0;
    let ew: f64 = east_west.trim().parse().unwrap();
    let ns: f64 = north_south.trim().parse().unwrap();
    let md: f64 = max_distance.trim().parse().unwrap();

    // 北
    if ns > 0.0 {
        num += (ns / md).abs().ceil() as i32;
    }

    // 東西
    if ew != 0.0 {
        num += 1;
        num += (ew / md).abs().ceil() as i32;
    }

    // 北から南へ向く場合、いったん東西へ向く
    if ew == 0.0 && ns < 0.0 {
        num += 1;
    }

    // 南
    if ns < 0.0 {
        num += 1;
        num += (ns / md).abs().ceil() as i32;
    }

    num
}

/// 標準入力から1行取得して返します。
fn read_line() -> String {
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    input
}
0