結果

問題 No.126 2基のエレベータ
ユーザー tonyu0
提出日時 2020-04-04 09:22:10
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 815 bytes
コンパイル時間 12,475 ms
コンパイル使用メモリ 402,028 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 18:36:57
合計ジャッジ時間 13,636 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();
    let s: i64 = itr.next().unwrap().parse().unwrap();

    let x = (a - s).abs();
    let y = (b - s).abs();
    if x <= y || s == 1 {
        // aがくる場合
        println!("{}", x + s);
    } else {
        // bがくる場合
        if a == 0 {
            // この時、bを使ってaのある場所にはいけない
            println!("{}", y + s + 1);
        } else {
            // bを使って1Fにいくか、aのある場所にいくか
            println!("{}", y + std::cmp::min(s - 1, x) + a);
        }
    }
}
0