結果

問題 No.1037 exhausted
ユーザー phsplsphspls
提出日時 2023-01-22 01:33:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 3,720 ms
コンパイル使用メモリ 144,212 KB
実行使用メモリ 33,372 KB
最終ジャッジ日時 2023-09-06 12:18:19
合計ジャッジ時間 3,140 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 46 ms
33,372 KB
testcase_13 AC 47 ms
33,044 KB
testcase_14 AC 46 ms
33,100 KB
testcase_15 AC 47 ms
33,108 KB
testcase_16 AC 47 ms
33,104 KB
testcase_17 AC 47 ms
33,020 KB
testcase_18 AC 46 ms
33,108 KB
testcase_19 AC 46 ms
33,048 KB
testcase_20 AC 24 ms
33,048 KB
testcase_21 AC 25 ms
33,104 KB
testcase_22 AC 24 ms
33,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn main() {
    let mut nvl = String::new();
    std::io::stdin().read_line(&mut nvl).ok();
    let nvl: Vec<usize> = nvl.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nvl[0];
    let v = nvl[1];
    let l = nvl[2];
    let mut points = (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();
            (temp[0], temp[1], temp[2])
        })
        .collect::<Vec<_>>();

    points.insert(0, (0, 0, 0));
    points.push((l, 0, 0));
    let mut dp = vec![vec![INF; v+1]; n+2];
    dp[0][v] = 0;
    for i in 1..=n+1 {
        let (cx, cv, cw) = points[i];
        let (px, _, _) = points[i-1];
        let diff = cx - px;
        if diff > v {
            println!("-1");
            return;
        }
        for j in 0..=v {
            if j+diff <= v {
                dp[i][j] = dp[i][j].min(dp[i-1][j+diff]);
                let nj = (j + cv).min(v);
                dp[i][nj] = dp[i][nj].min(dp[i-1][j+diff] + cw);
            }
        }
    }
    println!("{}", dp[n+1].iter().min().unwrap());
}
0