結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー phsplsphspls
提出日時 2022-10-14 23:10:16
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,617 bytes
コンパイル時間 1,527 ms
コンパイル使用メモリ 146,780 KB
実行使用メモリ 314,476 KB
最終ジャッジ日時 2023-09-08 23:34:52
合計ジャッジ時間 30,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
158,156 KB
testcase_01 AC 83 ms
158,148 KB
testcase_02 AC 46 ms
158,084 KB
testcase_03 AC 190 ms
158,080 KB
testcase_04 AC 143 ms
158,064 KB
testcase_05 AC 1,949 ms
314,440 KB
testcase_06 AC 192 ms
158,064 KB
testcase_07 AC 191 ms
157,956 KB
testcase_08 AC 1,773 ms
277,388 KB
testcase_09 AC 1,306 ms
239,196 KB
testcase_10 AC 1,258 ms
263,660 KB
testcase_11 AC 297 ms
182,184 KB
testcase_12 WA -
testcase_13 AC 191 ms
158,116 KB
testcase_14 AC 144 ms
158,088 KB
testcase_15 AC 1,896 ms
314,448 KB
testcase_16 AC 191 ms
158,064 KB
testcase_17 AC 190 ms
158,068 KB
testcase_18 AC 48 ms
158,072 KB
testcase_19 AC 47 ms
158,052 KB
testcase_20 AC 45 ms
158,072 KB
testcase_21 AC 46 ms
158,068 KB
testcase_22 AC 995 ms
213,796 KB
testcase_23 AC 446 ms
195,488 KB
testcase_24 AC 50 ms
157,996 KB
testcase_25 AC 44 ms
158,060 KB
testcase_26 AC 46 ms
158,056 KB
testcase_27 AC 505 ms
200,336 KB
testcase_28 AC 190 ms
157,996 KB
testcase_29 AC 144 ms
158,028 KB
testcase_30 AC 1,905 ms
314,416 KB
testcase_31 AC 191 ms
158,076 KB
testcase_32 AC 190 ms
158,100 KB
testcase_33 AC 190 ms
158,116 KB
testcase_34 AC 144 ms
158,120 KB
testcase_35 AC 1,893 ms
314,368 KB
testcase_36 AC 190 ms
158,104 KB
testcase_37 AC 189 ms
158,076 KB
testcase_38 AC 47 ms
158,088 KB
testcase_39 AC 45 ms
158,120 KB
testcase_40 AC 47 ms
158,008 KB
testcase_41 AC 563 ms
189,500 KB
testcase_42 AC 47 ms
158,084 KB
testcase_43 AC 139 ms
167,572 KB
testcase_44 AC 45 ms
158,124 KB
testcase_45 AC 49 ms
158,028 KB
testcase_46 AC 772 ms
196,208 KB
testcase_47 AC 45 ms
158,056 KB
testcase_48 AC 191 ms
158,052 KB
testcase_49 AC 145 ms
158,020 KB
testcase_50 AC 1,892 ms
314,476 KB
testcase_51 AC 192 ms
158,060 KB
testcase_52 AC 189 ms
158,156 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 43 ms
158,088 KB
testcase_57 AC 43 ms
158,096 KB
testcase_58 AC 44 ms
158,028 KB
testcase_59 AC 44 ms
158,060 KB
testcase_60 AC 42 ms
158,056 KB
testcase_61 AC 43 ms
158,120 KB
testcase_62 AC 44 ms
158,124 KB
testcase_63 AC 43 ms
158,056 KB
testcase_64 AC 261 ms
158,068 KB
testcase_65 AC 353 ms
158,068 KB
testcase_66 AC 333 ms
158,056 KB
testcase_67 AC 422 ms
158,064 KB
testcase_68 AC 43 ms
158,096 KB
testcase_69 AC 43 ms
158,120 KB
testcase_70 AC 43 ms
158,028 KB
testcase_71 AC 509 ms
158,064 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[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+a <= goal+a+1 && checked[pos+a] > cost + x {
            pque.push((Reverse(cost+x), pos+a));
            checked[pos+a] = cost+x;
        }
        if pos >= b && pos-b >= goal-b-1 && checked[pos-b] > cost + y {
            pque.push((Reverse(cost+y), pos-b));
            checked[pos-b] = cost+y;
        }
        if checked[goal] < INF { break; }
    }
    println!("{}", checked[goal]);
}
0