結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー phsplsphspls
提出日時 2022-10-15 00:23:39
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,936 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 144,532 KB
実行使用メモリ 200,336 KB
最終ジャッジ日時 2023-09-09 01:13:05
合計ジャッジ時間 16,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
158,164 KB
testcase_01 AC 66 ms
158,096 KB
testcase_02 AC 44 ms
158,032 KB
testcase_03 AC 44 ms
158,104 KB
testcase_04 AC 44 ms
158,132 KB
testcase_05 AC 215 ms
158,100 KB
testcase_06 AC 203 ms
158,100 KB
testcase_07 AC 44 ms
158,100 KB
testcase_08 AC 1,390 ms
166,416 KB
testcase_09 AC 1,131 ms
184,840 KB
testcase_10 AC 920 ms
159,584 KB
testcase_11 AC 236 ms
159,312 KB
testcase_12 AC 1,032 ms
172,668 KB
testcase_13 AC 41 ms
158,092 KB
testcase_14 AC 41 ms
158,112 KB
testcase_15 AC 210 ms
158,020 KB
testcase_16 AC 203 ms
158,084 KB
testcase_17 AC 41 ms
158,100 KB
testcase_18 AC 40 ms
158,092 KB
testcase_19 AC 40 ms
158,104 KB
testcase_20 AC 39 ms
158,020 KB
testcase_21 AC 40 ms
158,020 KB
testcase_22 AC 806 ms
166,012 KB
testcase_23 AC 445 ms
195,344 KB
testcase_24 AC 40 ms
158,084 KB
testcase_25 AC 40 ms
158,088 KB
testcase_26 AC 41 ms
158,088 KB
testcase_27 AC 502 ms
200,336 KB
testcase_28 AC 41 ms
158,084 KB
testcase_29 AC 40 ms
157,952 KB
testcase_30 AC 210 ms
158,052 KB
testcase_31 AC 198 ms
158,100 KB
testcase_32 AC 42 ms
158,100 KB
testcase_33 AC 40 ms
158,088 KB
testcase_34 AC 41 ms
158,092 KB
testcase_35 AC 211 ms
158,084 KB
testcase_36 AC 197 ms
158,096 KB
testcase_37 AC 40 ms
158,024 KB
testcase_38 AC 40 ms
158,016 KB
testcase_39 AC 41 ms
158,088 KB
testcase_40 AC 40 ms
158,084 KB
testcase_41 AC 41 ms
158,332 KB
testcase_42 AC 41 ms
158,108 KB
testcase_43 AC 134 ms
167,576 KB
testcase_44 AC 39 ms
158,028 KB
testcase_45 AC 40 ms
158,088 KB
testcase_46 AC 765 ms
196,132 KB
testcase_47 AC 41 ms
158,128 KB
testcase_48 AC 41 ms
158,108 KB
testcase_49 AC 41 ms
158,100 KB
testcase_50 AC 210 ms
158,104 KB
testcase_51 AC 200 ms
158,020 KB
testcase_52 AC 41 ms
158,088 KB
testcase_53 AC 40 ms
158,092 KB
testcase_54 AC 40 ms
158,044 KB
testcase_55 AC 40 ms
158,096 KB
testcase_56 AC 41 ms
158,020 KB
testcase_57 AC 40 ms
158,088 KB
testcase_58 AC 41 ms
158,100 KB
testcase_59 AC 40 ms
158,100 KB
testcase_60 AC 41 ms
158,028 KB
testcase_61 AC 41 ms
158,092 KB
testcase_62 AC 40 ms
158,028 KB
testcase_63 AC 41 ms
158,092 KB
testcase_64 AC 178 ms
158,088 KB
testcase_65 WA -
testcase_66 AC 224 ms
158,096 KB
testcase_67 WA -
testcase_68 AC 41 ms
158,104 KB
testcase_69 AC 40 ms
158,020 KB
testcase_70 AC 40 ms
158,104 KB
testcase_71 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const INF: usize = 1usize << 60;
const OFFSET: usize = 10000001;

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];
    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];

    let (t, start_cost) = if t < 0 {
            let temp = t.abs() as usize / b + if t % b as isize == 0 { 0 } else { 1 };
            let s = (b * temp) as isize + t;
            (s, temp * y)
        } else {
            let temp = t as usize / a;
            let s = t - (a * temp) as isize;
            (s, temp * x)
        };
    let t = (t + OFFSET as isize) as usize;
    let goal = t as usize;
    let mut checked = vec![INF; OFFSET*2+1];
    checked[OFFSET] = start_cost;
    let mut pque = BinaryHeap::new();
    pque.push((Reverse(start_cost), OFFSET));
    while let Some((Reverse(cost), pos)) = pque.pop() {
        if checked[goal] <= cost { break; }
        if checked[pos] < cost { continue; }
        if pos+1 < checked.len() && pos+1 <= goal && checked[pos+1] > cost + 1 {
            pque.push((Reverse(cost+1), pos+1));
            checked[pos+1] = cost+1;
        }
        if pos+a < checked.len() && pos < goal && checked[pos+a] > cost + x {
            pque.push((Reverse(cost+x), pos+a));
            checked[pos+a] = cost+x;
        }
        if pos >= b && pos > goal && checked[pos-b] > cost + y {
            pque.push((Reverse(cost+y), pos-b));
            checked[pos-b] = cost+y;
        }
    }
    println!("{}", checked[goal]);
}
0