結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー phsplsphspls
提出日時 2022-10-28 23:37:51
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 11,220 ms
コンパイル使用メモリ 378,396 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 02:54:56
合計ジャッジ時間 19,433 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: isize = 1isize << 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<isize> = 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<isize> = yb.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let y = yb[0];
    let b = yb[1];

    let mut result = INF;
    for i in 0..=10000000 {
        let mut cost = y * i;
        let start = -b * i;
        if start > t { continue; }
        cost += (t - start) / a * x + (t - start) % a;
        result = result.min(cost);
    }
    println!("{}", result);
}
0