結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー phsplsphspls
提出日時 2022-10-15 00:06:55
言語 Rust
(1.72.1)
結果
TLE  
実行時間 -
コード長 1,694 bytes
コンパイル時間 7,451 ms
コンパイル使用メモリ 155,808 KB
実行使用メモリ 419,948 KB
最終ジャッジ日時 2023-09-09 01:04:27
合計ジャッジ時間 16,482 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{collections::{BinaryHeap, HashMap}, cmp::Reverse};

const INF: usize = 1usize << 60;

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: isize = t.trim().parse().unwrap();
    let mut xa = String::new();
    std::io::stdin().read_line(&mut xa).ok();
    let xa: Vec<usize> = xa.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let x = xa[0];
    let a = xa[1] as isize;
    let mut yb = String::new();
    std::io::stdin().read_line(&mut yb).ok();
    let yb: Vec<usize> = yb.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let y = yb[0];
    let b = yb[1] as isize;

    let goal = t;
    let mut checked = HashMap::new();
    checked.insert(0isize, 0usize);
    let mut pque = BinaryHeap::new();
    pque.push((Reverse(0), 0isize));
    let get_cost = |p: isize, checked: &HashMap<isize, usize>| { *checked.get(&p).unwrap_or(&INF) };
    while let Some((Reverse(cost), pos)) = pque.pop() {
        if get_cost(goal, &checked) <= cost { break; }
        if get_cost(pos, &checked) < cost { continue; }
        let prev_cost = get_cost(pos+1, &checked);
        if pos+1 <= goal && prev_cost > cost + 1 {
            pque.push((Reverse(cost+1), pos+1));
            checked.insert(pos+1, cost+1);
        }
        if pos < goal && get_cost(pos+a, &checked) > cost + x {
            pque.push((Reverse(cost+x), pos+a));
            checked.insert(pos+a, cost+x);
        }
        if pos > goal && get_cost(pos-b, &checked) > cost + y {
            pque.push((Reverse(cost+y), pos-b));
            checked.insert(pos-b, cost+y);
        }
    }
    println!("{}", checked.get(&goal).unwrap());
}
0