結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー phsplsphspls
提出日時 2022-10-14 23:24:27
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,605 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 146,356 KB
実行使用メモリ 316,580 KB
最終ジャッジ日時 2023-09-08 23:49:02
合計ジャッジ時間 31,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
158,056 KB
testcase_01 AC 44 ms
158,016 KB
testcase_02 AC 42 ms
158,148 KB
testcase_03 AC 190 ms
158,184 KB
testcase_04 AC 190 ms
158,212 KB
testcase_05 AC 1,902 ms
314,360 KB
testcase_06 AC 190 ms
158,136 KB
testcase_07 AC 189 ms
158,136 KB
testcase_08 AC 1,764 ms
278,196 KB
testcase_09 AC 1,255 ms
240,084 KB
testcase_10 AC 1,248 ms
265,044 KB
testcase_11 AC 292 ms
182,628 KB
testcase_12 AC 1,728 ms
185,500 KB
testcase_13 AC 189 ms
158,068 KB
testcase_14 AC 145 ms
158,124 KB
testcase_15 AC 1,878 ms
314,800 KB
testcase_16 AC 189 ms
158,064 KB
testcase_17 AC 190 ms
158,128 KB
testcase_18 AC 48 ms
158,092 KB
testcase_19 AC 46 ms
158,060 KB
testcase_20 AC 43 ms
158,124 KB
testcase_21 AC 44 ms
158,092 KB
testcase_22 AC 988 ms
214,340 KB
testcase_23 AC 447 ms
195,992 KB
testcase_24 AC 49 ms
158,128 KB
testcase_25 AC 43 ms
158,120 KB
testcase_26 AC 44 ms
158,060 KB
testcase_27 AC 496 ms
201,336 KB
testcase_28 AC 189 ms
158,108 KB
testcase_29 AC 144 ms
158,100 KB
testcase_30 AC 1,886 ms
314,480 KB
testcase_31 AC 190 ms
158,096 KB
testcase_32 AC 189 ms
158,128 KB
testcase_33 AC 189 ms
158,112 KB
testcase_34 AC 144 ms
157,988 KB
testcase_35 AC 1,881 ms
316,580 KB
testcase_36 AC 191 ms
158,104 KB
testcase_37 AC 192 ms
158,124 KB
testcase_38 AC 47 ms
158,124 KB
testcase_39 AC 46 ms
158,148 KB
testcase_40 AC 48 ms
158,128 KB
testcase_41 AC 806 ms
188,808 KB
testcase_42 AC 46 ms
158,056 KB
testcase_43 AC 136 ms
169,124 KB
testcase_44 AC 42 ms
158,056 KB
testcase_45 AC 46 ms
158,120 KB
testcase_46 AC 760 ms
196,248 KB
testcase_47 AC 44 ms
158,100 KB
testcase_48 AC 188 ms
158,064 KB
testcase_49 AC 146 ms
158,116 KB
testcase_50 AC 1,872 ms
314,532 KB
testcase_51 AC 189 ms
158,092 KB
testcase_52 AC 187 ms
158,040 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 43 ms
158,116 KB
testcase_57 AC 42 ms
158,128 KB
testcase_58 AC 42 ms
158,124 KB
testcase_59 AC 41 ms
158,124 KB
testcase_60 AC 43 ms
158,128 KB
testcase_61 AC 42 ms
158,104 KB
testcase_62 AC 42 ms
158,100 KB
testcase_63 AC 40 ms
158,064 KB
testcase_64 AC 257 ms
158,100 KB
testcase_65 AC 344 ms
158,100 KB
testcase_66 AC 333 ms
158,056 KB
testcase_67 AC 419 ms
158,112 KB
testcase_68 AC 42 ms
158,124 KB
testcase_69 AC 42 ms
158,028 KB
testcase_70 AC 43 ms
158,056 KB
testcase_71 AC 505 ms
158,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


const INF: u32 = (1u32 << 30) - 1;
const OFFSET: usize = 20000001;

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] as u32;
    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] as u32;
    let b = yb[1];

    let t = (t + OFFSET as isize) as usize;
    let goal = t as usize;
    let mut checked = vec![INF; OFFSET*2+1];
    checked[OFFSET] = 0;
    let mut pque = BinaryHeap::new();
    pque.push((Reverse(0u32), 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