結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー phsplsphspls
提出日時 2022-11-23 16:22:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,696 bytes
コンパイル時間 5,791 ms
コンパイル使用メモリ 171,980 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 01:15:43
合計ジャッジ時間 3,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 11 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 9 ms
4,348 KB
testcase_24 AC 9 ms
4,348 KB
testcase_25 AC 9 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn main() {
    let mut temp = String::new();
    std::io::stdin().read_line(&mut temp).ok();
    let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let gx = temp[0];
    let gy = temp[1];
    let n = temp[2];
    let f = temp[3];
    let crystals = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            let x = temp[0];
            let y = temp[1];
            let c = temp[2];
            (x, y, c)
        })
        .collect::<Vec<_>>();

    let mut grid = vec![vec![vec![INF; gy+1]; gx+1]; 2];
    grid[0][0][0] = 0;
    grid[0][gx][gy] = (gx+gy)*f;
    for idx in 0..n {
        let (ax, ay, c) = crystals[idx];
        for used in 0..2 {
            for i in 0..=gx {
                for j in 0..=gy {
                    if i+1 <= gx {
                        grid[used][i+1][j] = grid[used][i+1][j].min(grid[used][i][j] + f);
                    }
                    if j+1 <= gy {
                        grid[used][i][j+1] = grid[used][i][j+1].min(grid[used][i][j] + f);
                    }
                    if used == 0 && i+ax <= gx && j+ay <= gy {
                        grid[1][i+ax][j+ay] = grid[1][i+ax][j+ay].min(grid[used][i][j] + c);
                    }
                }
            }
        }
        for i in 0..=gx {
            for j in 0..=gy {
                grid[0][i][j] = grid[0][i][j].min(grid[1][i][j]);
            }
        }
    }
    println!("{}", grid[0][gx][gy].min(grid[1][gx][gy]));
}
0