結果

問題 No.859 路線A、路線B、路線C
ユーザー phsplsphspls
提出日時 2023-01-02 16:58:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,951 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 145,044 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 23:42:33
合計ジャッジ時間 2,323 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut xyz = String::new();
    std::io::stdin().read_line(&mut xyz).ok();
    let xyz: Vec<isize> = xyz.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let x = xyz[0];
    let y = xyz[1];
    let z = xyz[2];
    let mut temp = String::new();
    std::io::stdin().read_line(&mut temp).ok();
    let temp: Vec<&str> = temp.trim().split_whitespace().collect();
    let s0 = temp[0].chars().nth(0).unwrap();
    let t0 = temp[1].parse::<isize>().unwrap();
    let mut temp = String::new();
    std::io::stdin().read_line(&mut temp).ok();
    let temp: Vec<&str> = temp.trim().split_whitespace().collect();
    let s1 = temp[0].chars().nth(0).unwrap();
    let t1 = temp[1].parse::<isize>().unwrap();

    let mut result = 1isize << 60;
    let s0sswitch = t0;
    let s0eswitch = if s0 == 'A' { x } else if s0 == 'B' { y } else { z } + 1 - t0;
    let s1sswitch = t1;
    let s1eswitch = if s1 == 'A' { x } else if s1 == 'B' { y } else { z } + 1 - t1;
    let totals = vec![x-1, y-1, z-1];
    for &middle in vec!['A', 'B', 'C'].iter() {
        if s0 == middle && middle == s1 {
            result = result.min((t0 - t1).abs());
        } else if s0 == s1 {
            result = result.min(s0sswitch + totals[middle as usize - 'A' as usize] + s1eswitch);
            result = result.min(s0eswitch + totals[middle as usize - 'A' as usize] + s1sswitch);
        } else if s0 == middle {
            result = result.min(s0sswitch + s1sswitch - 1);
            result = result.min(s0eswitch + s1eswitch - 1);
        } else if s1 == middle {
            result = result.min(s0sswitch + s1sswitch - 1);
            result = result.min(s0eswitch + s1eswitch - 1);
        } else {
            result = result.min(s0sswitch + totals[middle as usize - 'A' as usize] + s1eswitch);
            result = result.min(s0eswitch + totals[middle as usize - 'A' as usize] + s1sswitch);
        }
    }
    println!("{}", result);
}
0