結果

問題 No.1037 exhausted
ユーザー tonyu0tonyu0
提出日時 2020-04-25 14:13:47
言語 Rust
(1.72.1)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 5,450 ms
コンパイル使用メモリ 143,520 KB
実行使用メモリ 33,896 KB
最終ジャッジ日時 2023-08-06 22:12:59
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
33,884 KB
testcase_01 AC 24 ms
33,872 KB
testcase_02 AC 23 ms
33,796 KB
testcase_03 AC 24 ms
33,796 KB
testcase_04 AC 24 ms
33,812 KB
testcase_05 AC 24 ms
33,872 KB
testcase_06 AC 24 ms
33,868 KB
testcase_07 AC 25 ms
33,836 KB
testcase_08 AC 24 ms
33,876 KB
testcase_09 AC 25 ms
33,876 KB
testcase_10 AC 25 ms
33,880 KB
testcase_11 AC 24 ms
33,800 KB
testcase_12 AC 47 ms
33,888 KB
testcase_13 AC 48 ms
33,884 KB
testcase_14 AC 48 ms
33,876 KB
testcase_15 AC 47 ms
33,836 KB
testcase_16 AC 48 ms
33,888 KB
testcase_17 AC 48 ms
33,896 KB
testcase_18 AC 49 ms
33,876 KB
testcase_19 AC 48 ms
33,848 KB
testcase_20 AC 45 ms
33,888 KB
testcase_21 AC 43 ms
33,880 KB
testcase_22 AC 38 ms
33,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::io::*;
const INF: usize = 1 << 60;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let v: usize = itr.next().unwrap().parse().unwrap();
    let l: usize = itr.next().unwrap().parse().unwrap();
    let mut a = Vec::new();
    a.push((0, 0, 0));
    for _ in 0..n {
        a.push((
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
        ));
    }
    a.push((l, 0, 0));

    let mut dp: Vec<Vec<usize>> = vec![vec![INF; 2020]; 2020];
    dp[0][v] = 0;

    for i in 0..n + 1 {
        for j in 0..v + 1 {
            let k = min(j + a[i].1, v);
            let diff = a[i + 1].0 - a[i].0;
            if k >= diff {
                dp[i + 1][k - diff] = min(dp[i + 1][k - diff], dp[i][j] + a[i].2);
            }
            if j >= diff {
                dp[i + 1][j - diff] = min(dp[i + 1][j - diff], dp[i][j]);
            }
        }
    }
    let mut ans = INF;
    for i in 0..v + 1 {
        if dp[n + 1][i] != INF {
            ans = min(ans, dp[n + 1][i]);
        }
    }
    if ans == INF {
        println!("-1",)
    } else {
        println!("{}", ans);
    }
}
0